#include<stdio.h>
int R;
int box[101][101][101];
int xx[6]={0,0,0,0,1,-1};
int yy[6]={0,0,1,-1,0,0};
int zz[6]={1,-1,0,0,0,0};
int f, r;
int X, Y, Z;
struct data{
int x, y, z, l;
void inq(int zz, int yy, int xx, int ll){
if(xx<1 || yy<1 || zz<1 || xx>X || yy>Y || zz>Z) return;
if(box[zz][yy][xx]) return;
x=xx, y=yy, z=zz, l=ll, r++;
box[z][y][x]=1;
R--;
}
}q[1100000];
void bfs(){
while(f<r){
for(int i=0; i<6; i++) q[r].inq(q[f].z+zz[i], q[f].y+yy[i], q[f].x+xx[i], q[f].l+1);
f++;
}
}
int main(){
int i, j, k;
scanf("%d %d %d", &X, &Y, &Z);
for(i=1; i<=Z; i++) for(j=1; j<=Y; j++) for(k=1; k<=X; k++) {
scanf("%d", &box[i][j][k]);
if(!box[i][j][k]) R++;
if(box[i][j][k]==1) q[r].z=i, q[r].y=j, q[r].x=k, r++;
}
bfs();
printf("%d", R? -1:q[r-1].l);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
22300 KB |
Output is correct |
2 |
Correct |
4 ms |
22300 KB |
Output is correct |
3 |
Correct |
0 ms |
22300 KB |
Output is correct |
4 |
Correct |
0 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
22300 KB |
Output is correct |
2 |
Correct |
0 ms |
22300 KB |
Output is correct |
3 |
Correct |
4 ms |
22300 KB |
Output is correct |
4 |
Correct |
0 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
22300 KB |
Output is correct |
2 |
Correct |
0 ms |
22300 KB |
Output is correct |
3 |
Correct |
0 ms |
22300 KB |
Output is correct |
4 |
Correct |
0 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
22300 KB |
Output is correct |
2 |
Correct |
20 ms |
22300 KB |
Output is correct |
3 |
Correct |
28 ms |
22300 KB |
Output is correct |
4 |
Correct |
40 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
22300 KB |
Output is correct |
2 |
Correct |
4 ms |
22300 KB |
Output is correct |
3 |
Correct |
24 ms |
22300 KB |
Output is correct |
4 |
Correct |
8 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
22300 KB |
Output is correct |
2 |
Correct |
20 ms |
22300 KB |
Output is correct |
3 |
Correct |
32 ms |
22300 KB |
Output is correct |
4 |
Correct |
12 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
22300 KB |
Output is correct |
2 |
Correct |
32 ms |
22300 KB |
Output is correct |
3 |
Correct |
88 ms |
22300 KB |
Output is correct |
4 |
Correct |
8 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
22300 KB |
Output is correct |
2 |
Correct |
88 ms |
22300 KB |
Output is correct |
3 |
Correct |
88 ms |
22300 KB |
Output is correct |
4 |
Correct |
104 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
22300 KB |
Output is correct |
2 |
Correct |
124 ms |
22300 KB |
Output is correct |
3 |
Correct |
124 ms |
22300 KB |
Output is correct |
4 |
Correct |
116 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
22300 KB |
Output is correct |
2 |
Correct |
56 ms |
22300 KB |
Output is correct |
3 |
Correct |
156 ms |
22300 KB |
Output is correct |
4 |
Correct |
40 ms |
22300 KB |
Output is correct |