SWexpertAcademy

5653. [모의 SW 역량테스트] 줄기세포배양

먼지의삶 2019. 7. 26. 01:07
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>

using namespace std;

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

struct node {
	int x;
	int y;
	int time;
	node(int a, int b, int c) {
		x = a;
		y = b;
		time = c;
	}
};

int tc;
int map[800][800];
int n, m, k;
int answer;

void initial() {
	for (int i = 0; i < 800; i++) {
		for (int j = 0; j < 800; j++) {
			map[i][j] = 0;
		}
	}
}

int main() {
	scanf("%d", &tc);
	for (int tn = 1; tn <= tc; tn++) {
		scanf("%d %d %d", &n, &m, &k);
		initial();//초기화 과정
		answer = 0;

		queue<node> q[11];//배양 시간 고려함

		for (int i = 400; i < 400 + n; i++) {
			for (int j = 400; j < 400 + m; j++) {
				scanf("%d", &map[i][j]);
				if (map[i][j]) {
					int index = map[i][j];
					q[index].push(node(i, j, index * 2));
				}
					
			}
		}

		while (k--) {//시간동안..
			for (int i = 10; i >= 1; i--) {//큰녀석이 우선시 되야해서, 방향성을 작아지는것으로 설정해야합니다.
				int size = q[i].size();//size있는경우, 시간 없으면 고려 안하기 위해서

				for (int j = 0; j < size; j++) {
					int x = q[i].front().x;
					int y = q[i].front().y;
					int time = q[i].front().time;
					q[i].pop();
					time--;
					if (map[x][y] > time) {//활성화 체크하는거임
						for (int d = 0; d < 4; d++) {
							int nx = x + dx[d];
							int ny = y + dy[d];
							if (map[nx][ny] == 0) { 
								map[nx][ny] = map[x][y];
								q[i].push(node(nx, ny, map[nx][ny] * 2));//쓸놈들 넣어주기
							}
						}
					}
					if (time > 0) {
						q[i].push(node(x, y, time));//썻던놈 다시 넣어주기
					}
				}

			}
		}

		for (int i = 1; i < 11; i++) {
			answer += q[i].size();
		}

		
		
		printf("#%d %d\n", tn, answer);
	}
}

다른거보다 정보저장을 어떻게 해야할지 많이 고민했던 문제, 그냥 구조체로 한큐에 때려잡았다.