This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |