#include <stdio.h>
#include <queue>
using namespace std;
queue <int> q;
int m, n, h, a[101][101][101], d[101][101][101], ans;
int dz[6]={0,0,0,0,1,-1}, dy[6]={0,1,0,-1,0,0}, dx[6]={1,0,-1,0,0,0};
void input(void)
{
int i, j, k;
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",&a[i][j][k]);
if(a[i][j][k]==1)
{
q.push(i);
q.push(j);
q.push(k);
}
}
}
void process(void)
{
int i, j, k, z, y, x, tz, ty, tx;
while(!q.empty())
{
z=q.front();
q.pop();
y=q.front();
q.pop();
x=q.front();
q.pop();
for(i=0 ; i<=5 ; i++)
{
tz=z+dz[i];
ty=y+dy[i];
tx=x+dx[i];
if(tz>=1 && tz<=h && ty>=1 && ty<=n && tx>=1 && tx<=m)
if(a[tz][ty][tx]==0)
{
a[tz][ty][tx]=1;
d[tz][ty][tx]=d[z][y][x]+1;
q.push(tz);
q.push(ty);
q.push(tx);
}
}
}
for(i=1 ; i<=h ; i++)
for(j=1 ; j<=n ; j++)
for(k=1 ; k<=m ; k++)
{
if(a[i][j][k]==0)
{
ans=-1;
return;
}
if(ans<d[i][j][k])
ans=d[i][j][k];
}
}
void output(void)
{
printf("%d",ans);
}
int main(void)
{
input();
process();
output();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9292 KB |
Output is correct |
2 |
Correct |
0 ms |
9292 KB |
Output is correct |
3 |
Correct |
0 ms |
9292 KB |
Output is correct |
4 |
Correct |
0 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9292 KB |
Output is correct |
2 |
Correct |
4 ms |
9292 KB |
Output is correct |
3 |
Correct |
4 ms |
9292 KB |
Output is correct |
4 |
Correct |
0 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9292 KB |
Output is correct |
2 |
Correct |
0 ms |
9292 KB |
Output is correct |
3 |
Correct |
0 ms |
9292 KB |
Output is correct |
4 |
Correct |
0 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
9552 KB |
Output is correct |
2 |
Correct |
12 ms |
9292 KB |
Output is correct |
3 |
Correct |
28 ms |
10096 KB |
Output is correct |
4 |
Correct |
44 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9424 KB |
Output is correct |
2 |
Correct |
4 ms |
9420 KB |
Output is correct |
3 |
Correct |
16 ms |
9960 KB |
Output is correct |
4 |
Correct |
8 ms |
9420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
9292 KB |
Output is correct |
2 |
Correct |
24 ms |
9424 KB |
Output is correct |
3 |
Correct |
40 ms |
9552 KB |
Output is correct |
4 |
Correct |
8 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
9556 KB |
Output is correct |
2 |
Correct |
44 ms |
9292 KB |
Output is correct |
3 |
Correct |
132 ms |
10084 KB |
Output is correct |
4 |
Correct |
12 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
9556 KB |
Output is correct |
2 |
Correct |
112 ms |
10080 KB |
Output is correct |
3 |
Correct |
100 ms |
9952 KB |
Output is correct |
4 |
Correct |
112 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
9952 KB |
Output is correct |
2 |
Correct |
140 ms |
10212 KB |
Output is correct |
3 |
Correct |
144 ms |
10492 KB |
Output is correct |
4 |
Correct |
132 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
9952 KB |
Output is correct |
2 |
Correct |
60 ms |
9292 KB |
Output is correct |
3 |
Correct |
188 ms |
10768 KB |
Output is correct |
4 |
Correct |
48 ms |
9292 KB |
Output is correct |