답안 #1177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1177 2013-06-28T14:46:19 Z kriii 토마토 (KOI13_tomato) C++
16 / 16
132 ms 12804 KB
#include <stdio.h>

int N,M,A,V[1000][1000];
int U[1000000],D[1000][1000];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int trans(int x, int y){return x * M + y;}

int main()
{
	int i,j,x,y,px,py;
	int head=-1,tail=-1;

	scanf ("%d %d",&M,&N);
	for (i=0;i<N;i++) for (j=0;j<M;j++){
		scanf ("%d",&V[i][j]);
		if (V[i][j] == 1) U[++head] = trans(i,j);
	}

	while (tail < head){
		++tail; x = U[tail] / M; y = U[tail] % M;
		if (A < D[x][y])
			A = D[x][y];

		for (i=0;i<4;i++){
			px = x + dx[i]; py = y + dy[i];
			if (px < 0 || px >= N || py < 0 || py >= M) continue;

			if (V[px][py] == 0){
				V[px][py] = 1;
				D[px][py] = D[x][y] + 1;
				U[++head] = trans(px,py);
			}
		}
	}

	for (i=0;i<N;i++) for (j=0;j<M;j++) if (V[i][j] == 0) A = -1;
	printf ("%d\n",A);

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12804 KB Output is correct
2 Correct 0 ms 12804 KB Output is correct
3 Correct 0 ms 12804 KB Output is correct
4 Correct 0 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12804 KB Output is correct
2 Correct 0 ms 12804 KB Output is correct
3 Correct 0 ms 12804 KB Output is correct
4 Correct 0 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12804 KB Output is correct
2 Correct 0 ms 12804 KB Output is correct
3 Correct 0 ms 12804 KB Output is correct
4 Correct 0 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12804 KB Output is correct
2 Correct 4 ms 12804 KB Output is correct
3 Correct 0 ms 12804 KB Output is correct
4 Correct 0 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12804 KB Output is correct
2 Correct 0 ms 12804 KB Output is correct
3 Correct 4 ms 12804 KB Output is correct
4 Correct 4 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12804 KB Output is correct
2 Correct 4 ms 12804 KB Output is correct
3 Correct 0 ms 12804 KB Output is correct
4 Correct 4 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 12804 KB Output is correct
2 Correct 20 ms 12804 KB Output is correct
3 Correct 12 ms 12804 KB Output is correct
4 Correct 8 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 12804 KB Output is correct
2 Correct 48 ms 12804 KB Output is correct
3 Correct 8 ms 12804 KB Output is correct
4 Correct 8 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 12804 KB Output is correct
2 Correct 88 ms 12804 KB Output is correct
3 Correct 12 ms 12804 KB Output is correct
4 Correct 64 ms 12804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 12804 KB Output is correct
2 Correct 132 ms 12804 KB Output is correct
3 Correct 132 ms 12804 KB Output is correct
4 Correct 96 ms 12804 KB Output is correct