[SWEA 5653] 줄기세포배양
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;
}