티스토리 뷰

SW Expert Academy :: SWEA :: 5653 :: 줄기세포배양


출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRJ8EKe48DFAUo


#include <bits/stdc++.h>

using namespace std;


struct cell {

int life, x, y;

};


int t, tc, ans;

int N, M, K;

int J[450][450];

int dx[] = { 0,0,1,-1 }, dy[] = { 1,-1,0,0 };

queue<cell> q[11];


void input() {

for (int i = 0;i < 11;i++)while (!q[i].empty()) q[i].pop();

ans = 0; memset(J, 0, sizeof(J)); cin >> N >> M >> K; 

for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) {

cin >> J[i + 175][j + 175];

if (J[i + 175][j + 175]) {

q[J[i + 175][j + 175]].push({ 2 * J[i + 175][j + 175], i + 175, j + 175 });

}

}

}


void cal() {

for (int i = 0; i <= K; ++i) {

for (int j = 10; j >= 1; --j) {

int q_s = q[j].size();

for (int k = 0; k < q_s; ++k) {

cell cl = q[j].front(); q[j].pop();

if (cl.life > j) {

if (J[cl.x][cl.y]>0) {

J[cl.x][cl.y] *= -1; ans++;

}

q[j].push({ cl.life - 1,cl.x,cl.y });

}

else if (cl.life == j) {

q[j].push({ j - 1,cl.x,cl.y });

for (int l = 0; l < 4; ++l) {

int nx = cl.x + dx[l];int ny = cl.y + dy[l];

if (J[nx][ny]) continue;

q[j].push({ 2 * j,nx,ny });J[nx][ny] = j;

}

}

else if (j > cl.life && cl.life) q[j].push({ cl.life - 1,cl.x,cl.y });

else ans--;

}

}

}

}


int main() {

ios::sync_with_stdio(false); cin.tie(0);

cin >> t;

for (tc = 1; tc <= t; ++tc) {

input(); cal();

cout << "#" << tc << " " << ans << '\n';

}

return 0;

}



'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 5789] 현주의 상자 바꾸기  (0) 2018.10.10
[SWEA 5656] 벽돌 깨기  (0) 2018.09.29
[SWEA 5658] 보물상자 비밀번호  (0) 2018.09.21
[SWEA 5644] 무선 충전  (0) 2018.09.21
[SWEA 5648] 원자 소멸 시뮬레이션  (0) 2018.09.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함