#include<cstdio>
#include<queue>
using namespace std;
int m,n,h,i,j,k,a[105][105][105],dx[6]{1,-1},dy[6]{0,0,1,-1},dz[6]{0,0,0,0,1,-1},mt;
struct zp{
int x,y,z;
}tempzp;
pair<zp,int>temppair;
queue<pair<zp,int> >q;
int main()
{
scanf("%d %d %d",&m,&n,&h);
for(i=0;i<h;i++)
for(j=0;j<n;j++)
for(k=0;k<m;k++)
scanf("%d",&a[i][j][k]);
for(i=0;i<h;i++)
for(j=0;j<n;j++)
for(k=0;k<m;k++)
if(a[i][j][k]==1){
tempzp.x=i;
tempzp.y=j;
tempzp.z=k;
q.push(make_pair(tempzp,0));
}
while(!q.empty()) {
temppair=q.front();
q.pop();
if(temppair.second>mt)mt=temppair.second;
for(i=0;i<6;i++) {
tempzp.x=temppair.first.x+dx[i];
tempzp.y=temppair.first.y+dy[i];
tempzp.z=temppair.first.z+dz[i];
if(tempzp.x<0||tempzp.y<0||tempzp.z<0||tempzp.x>=h||tempzp.y>=n||tempzp.z>=m||a[tempzp.x][tempzp.y][tempzp.z])continue;
a[tempzp.x][tempzp.y][tempzp.z]=1;
q.push(make_pair(tempzp,temppair.second+1));
}
}
for(i=0;i<h;i++)
for(j=0;j<n;j++)
for(k=0;k<m;k++)
if(!a[i][j][k]) {
puts("-1");
return 0;
}
printf("%d",mt);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6104 KB |
Output is correct |
2 |
Correct |
0 ms |
6104 KB |
Output is correct |
3 |
Correct |
0 ms |
6104 KB |
Output is correct |
4 |
Correct |
0 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6104 KB |
Output is correct |
2 |
Correct |
5 ms |
6232 KB |
Output is correct |
3 |
Correct |
0 ms |
6104 KB |
Output is correct |
4 |
Correct |
0 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
6104 KB |
Output is correct |
2 |
Correct |
0 ms |
6104 KB |
Output is correct |
3 |
Correct |
3 ms |
6104 KB |
Output is correct |
4 |
Correct |
0 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
6496 KB |
Output is correct |
2 |
Correct |
12 ms |
6104 KB |
Output is correct |
3 |
Correct |
11 ms |
7160 KB |
Output is correct |
4 |
Correct |
38 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6236 KB |
Output is correct |
2 |
Correct |
6 ms |
6232 KB |
Output is correct |
3 |
Correct |
11 ms |
7024 KB |
Output is correct |
4 |
Correct |
10 ms |
6236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
6232 KB |
Output is correct |
2 |
Correct |
25 ms |
6236 KB |
Output is correct |
3 |
Correct |
41 ms |
6496 KB |
Output is correct |
4 |
Correct |
15 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
6496 KB |
Output is correct |
2 |
Correct |
45 ms |
6104 KB |
Output is correct |
3 |
Correct |
88 ms |
7164 KB |
Output is correct |
4 |
Correct |
16 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
6496 KB |
Output is correct |
2 |
Correct |
96 ms |
7156 KB |
Output is correct |
3 |
Correct |
84 ms |
7028 KB |
Output is correct |
4 |
Correct |
130 ms |
6628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
7024 KB |
Output is correct |
2 |
Correct |
141 ms |
7304 KB |
Output is correct |
3 |
Correct |
134 ms |
7708 KB |
Output is correct |
4 |
Correct |
127 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
7024 KB |
Output is correct |
2 |
Correct |
63 ms |
6104 KB |
Output is correct |
3 |
Correct |
184 ms |
7984 KB |
Output is correct |
4 |
Correct |
49 ms |
6104 KB |
Output is correct |