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 U[1000000],V[100][100][100],D[100][100][100];
int M,N,H,A;
int dx[6] = {1,-1,0,0,0,0};
int dy[6] = {0,0,1,-1,0,0};
int dz[6] = {0,0,0,0,1,-1};
int trans(int x, int y, int z){return z * M * N + y + x * N;}
int main()
{
int i,j,k,x,y,z,px,py,pz;
int head = -1, tail = -1;
scanf ("%d %d %d",&N,&M,&H);
for (k=0;k<H;k++) for (i=0;i<M;i++) for (j=0;j<N;j++){
scanf ("%d",&V[i][j][k]);
if (V[i][j][k] == 1) U[++head] = trans(i,j,k);
}
while (tail < head){
++tail; y = U[tail] % N; x = (U[tail] / N) % M; z = U[tail] / (N * M);
if (A < D[x][y][z])
A = D[x][y][z];
for (i=0;i<6;i++){
px = x + dx[i]; py = y + dy[i]; pz = z + dz[i];
if (px < 0 || px >= M || py < 0 || py >= N || pz < 0 || pz >= H) continue;
if (V[px][py][pz] == 0){
V[px][py][pz] = 1;
D[px][py][pz] = D[x][y][z] + 1;
U[++head] = trans(px,py,pz);
}
}
}
for (i=0;i<M;i++) for (j=0;j<N;j++) for (k=0;k<H;k++) if (V[i][j][k] == 0) A = -1;
printf ("%d",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... |