#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 |
1 |
Correct |
0 ms |
12604 KB |
Output is correct |
2 |
Correct |
3 ms |
12604 KB |
Output is correct |
3 |
Correct |
0 ms |
12604 KB |
Output is correct |
4 |
Correct |
0 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12604 KB |
Output is correct |
2 |
Correct |
2 ms |
12604 KB |
Output is correct |
3 |
Correct |
3 ms |
12604 KB |
Output is correct |
4 |
Correct |
1 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
12604 KB |
Output is correct |
2 |
Correct |
0 ms |
12604 KB |
Output is correct |
3 |
Correct |
2 ms |
12604 KB |
Output is correct |
4 |
Correct |
0 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
12604 KB |
Output is correct |
2 |
Correct |
26 ms |
12604 KB |
Output is correct |
3 |
Correct |
36 ms |
12604 KB |
Output is correct |
4 |
Correct |
45 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12604 KB |
Output is correct |
2 |
Correct |
3 ms |
12604 KB |
Output is correct |
3 |
Correct |
29 ms |
12604 KB |
Output is correct |
4 |
Correct |
9 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
12604 KB |
Output is correct |
2 |
Correct |
28 ms |
12604 KB |
Output is correct |
3 |
Correct |
43 ms |
12604 KB |
Output is correct |
4 |
Correct |
11 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
12604 KB |
Output is correct |
2 |
Correct |
41 ms |
12604 KB |
Output is correct |
3 |
Correct |
115 ms |
12604 KB |
Output is correct |
4 |
Correct |
14 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
12604 KB |
Output is correct |
2 |
Correct |
122 ms |
12604 KB |
Output is correct |
3 |
Correct |
106 ms |
12604 KB |
Output is correct |
4 |
Correct |
138 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
12604 KB |
Output is correct |
2 |
Correct |
155 ms |
12604 KB |
Output is correct |
3 |
Correct |
162 ms |
12604 KB |
Output is correct |
4 |
Correct |
131 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
12604 KB |
Output is correct |
2 |
Correct |
61 ms |
12604 KB |
Output is correct |
3 |
Correct |
208 ms |
12604 KB |
Output is correct |
4 |
Correct |
53 ms |
12604 KB |
Output is correct |