#include<stdio.h>
int n, m, h;
int map[102][102][102], time[102][102][102], check[102][102][102];
int out;
int q[2000004][4], r=0, f=0;
int main()
{
int i, j, k, a=0, maxt=0;
int y, x, z, st;
int dz[6]={1,-1,0,0,0,0};
int dy[6]={0,0,-1,0,1,0};
int dx[6]={0,0,0,1,0,-1};
scanf("%d %d %d",&m,&n,&h);
for(i=1 ; i<=h ; i++)
{
for(j=1 ; j<=n ; j++)
{
for(k=1 ; k<=m ; k++)
{
scanf("%d",&map[i][j][k]);
if(map[i][j][k]==0) a++;
if(map[i][j][k]==1)
{
r++;
q[r][1]=i, q[r][2]=j, q[r][3]=k;
}
}
}
}
st=r;
do
{
f++;
z=q[f][1], y=q[f][2], x=q[f][3];
check[z][y][x]=1;
for(i=0 ; i<6 ; i++)
{
if(z+dz[i]>=1 && z+dz[i]<=h && y+dy[i]>=1 && y+dy[i]<=n && x+dx[i]>=1 && x+dx[i]<=m && check[z+dz[i]][y+dy[i]][x+dx[i]]==0 && map[z+dz[i]][y+dy[i]][x+dx[i]]==0)
{
check[z+dz[i]][y+dy[i]][x+dx[i]]=1;
r++;
q[r][1]=z+dz[i], q[r][2]=y+dy[i], q[r][3]=x+dx[i];
time[z+dz[i]][y+dy[i]][x+dx[i]]=time[z][y][x]+1;
if(maxt<time[z+dz[i]][y+dy[i]][x+dx[i]]) maxt=time[z+dz[i]][y+dy[i]][x+dx[i]];
}
}
}while(f<r);
if(r-st==a) out=maxt;
else if(a==0) out=0;
else if(r-st!=a) out=-1;
printf("%d",out);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
44772 KB |
Output is correct |
2 |
Correct |
0 ms |
44772 KB |
Output is correct |
3 |
Correct |
0 ms |
44772 KB |
Output is correct |
4 |
Correct |
0 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
44772 KB |
Output is correct |
2 |
Correct |
8 ms |
44772 KB |
Output is correct |
3 |
Correct |
4 ms |
44772 KB |
Output is correct |
4 |
Correct |
0 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
44772 KB |
Output is correct |
2 |
Correct |
0 ms |
44772 KB |
Output is correct |
3 |
Correct |
0 ms |
44772 KB |
Output is correct |
4 |
Correct |
0 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
44772 KB |
Output is correct |
2 |
Correct |
16 ms |
44772 KB |
Output is correct |
3 |
Correct |
20 ms |
44772 KB |
Output is correct |
4 |
Correct |
40 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
44772 KB |
Output is correct |
2 |
Correct |
0 ms |
44772 KB |
Output is correct |
3 |
Correct |
16 ms |
44772 KB |
Output is correct |
4 |
Correct |
8 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
44772 KB |
Output is correct |
2 |
Correct |
24 ms |
44772 KB |
Output is correct |
3 |
Correct |
36 ms |
44772 KB |
Output is correct |
4 |
Correct |
8 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
44772 KB |
Output is correct |
2 |
Correct |
36 ms |
44772 KB |
Output is correct |
3 |
Correct |
108 ms |
44772 KB |
Output is correct |
4 |
Correct |
12 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
44772 KB |
Output is correct |
2 |
Correct |
108 ms |
44772 KB |
Output is correct |
3 |
Correct |
80 ms |
44772 KB |
Output is correct |
4 |
Correct |
116 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
44772 KB |
Output is correct |
2 |
Correct |
116 ms |
44772 KB |
Output is correct |
3 |
Correct |
140 ms |
44772 KB |
Output is correct |
4 |
Correct |
124 ms |
44772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
168 ms |
44772 KB |
Output is correct |
2 |
Correct |
52 ms |
44772 KB |
Output is correct |
3 |
Correct |
188 ms |
44772 KB |
Output is correct |
4 |
Correct |
44 ms |
44772 KB |
Output is correct |