Submission #3146

# Submission time Handle Problem Language Result Execution time Memory
3146 2013-08-26T08:07:01 Z movie_jo 토마토 (3차원) (KOI13_tomato3D) C
20 / 20
124 ms 16712 KB
#include <stdio.h>

struct QUEUE {
	int i,j,k;
} q[1000001];
int f = 0, l = 0;

int x[100][100][100];
int I, J, K, remain = 0;

void inqueue(int i, int j, int k)
{
	q[l].i = i;
	q[l].j = j;
	q[l].k = k;
	l++;
}

int main(void)
{
	int i, j, k, t = 0, s = 0;

	scanf("%d %d %d", &I, &J, &K);

	for(k = 0; k < K; k++)
	{
		for(j = 0; j < J; j++)
		{
			for(i = 0; i < I; i++)
			{
				scanf("%d", &x[k][j][i]);

				if(x[k][j][i] == 1)
					inqueue(i, j, k);
				else if(x[k][j][i] == 0)
					remain++;
			}
		}
	}

	while(t < l)
	{
		for(t = l; f < t; f++)
		{
			i = q[f].i;
			j = q[f].j;
			k = q[f].k;
			
			if(k > 0 && x[k - 1][j][i] == 0)
			{
				inqueue(i, j, k - 1);
				x[k - 1][j][i] = 1;
				remain--;
			}
			if(k < K - 1 && x[k + 1][j][i] == 0)
			{
				inqueue(i, j, k + 1);
				x[k + 1][j][i] = 1;
				remain--;
			}

			if(j > 0 && x[k][j - 1][i] == 0)
			{
				inqueue(i, j - 1, k);
				x[k][j - 1][i] = 1;
				remain--;
			}
			if(j < J - 1 && x[k][j + 1][i] == 0)
			{
				inqueue(i, j + 1, k);
				x[k][j + 1][i] = 1;
				remain--;
			}

			if(i > 0 && x[k][j][i - 1] == 0)
			{
				inqueue(i - 1, j, k);
				x[k][j][i - 1] = 1;
				remain--;
			}
			if(i < I - 1 && x[k][j][i + 1] == 0)
			{
				inqueue(i + 1, j, k);
				x[k][j][i + 1] = 1;
				remain--;
			}
		}
		s++;
	}

	if(remain > 0)
		printf("-1\n");
	else
		printf("%d\n", s - 1);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16712 KB Output is correct
2 Correct 4 ms 16712 KB Output is correct
3 Correct 0 ms 16712 KB Output is correct
4 Correct 0 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16712 KB Output is correct
2 Correct 4 ms 16712 KB Output is correct
3 Correct 0 ms 16712 KB Output is correct
4 Correct 0 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16712 KB Output is correct
2 Correct 0 ms 16712 KB Output is correct
3 Correct 0 ms 16712 KB Output is correct
4 Correct 0 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16712 KB Output is correct
2 Correct 16 ms 16712 KB Output is correct
3 Correct 16 ms 16712 KB Output is correct
4 Correct 32 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16712 KB Output is correct
2 Correct 4 ms 16712 KB Output is correct
3 Correct 20 ms 16712 KB Output is correct
4 Correct 8 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 16712 KB Output is correct
2 Correct 16 ms 16712 KB Output is correct
3 Correct 28 ms 16712 KB Output is correct
4 Correct 4 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 16712 KB Output is correct
2 Correct 36 ms 16712 KB Output is correct
3 Correct 84 ms 16712 KB Output is correct
4 Correct 12 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 16712 KB Output is correct
2 Correct 84 ms 16712 KB Output is correct
3 Correct 68 ms 16712 KB Output is correct
4 Correct 88 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 16712 KB Output is correct
2 Correct 108 ms 16712 KB Output is correct
3 Correct 112 ms 16712 KB Output is correct
4 Correct 104 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 16712 KB Output is correct
2 Correct 56 ms 16712 KB Output is correct
3 Correct 124 ms 16712 KB Output is correct
4 Correct 44 ms 16712 KB Output is correct