#include<cstdio>
int d[100][100][100];
int a[100][100][100];
int qx[1000000];
int qy[1000000];
int qz[1000000];
int qn;
int px[6]={1,-1,0,0,0,0};
int py[6]={0,0,1,-1,0,0};
int pz[6]={0,0,0,0,1,-1};
int main()
{
int x,y,z,dest=0;
int i,j,k,n,m,l;
scanf("%d%d%d",&l,&m,&n);
for(i=0;i<n;i++)for(j=0;j<m;j++)for(k=0;k<l;k++)scanf("%d",&a[i][j][k]);
for(i=0;i<n;i++)for(j=0;j<m;j++)for(k=0;k<l;k++)
{
if(a[i][j][k]==1)
{
d[i][j][k]=1;
qx[qn]=i;
qy[qn]=j;
qz[qn]=k;
qn++;
}
if(a[i][j][k]>=0)
dest++;
}
for(i=0;i<qn;i++)
{
x=qx[i];
y=qy[i];
z=qz[i];
for(j=0;j<6;j++)
{
x+=px[j];
y+=py[j];
z+=pz[j];
if(x>=0&&x<n&&y>=0&&y<m&&z>=0&&z<l&&a[x][y][z]==0&&!d[x][y][z])
{
d[x][y][z]=d[qx[i]][qy[i]][qz[i]]+1;
qx[qn]=x;
qy[qn]=y;
qz[qn]=z;
qn++;
}
x-=px[j];
y-=py[j];
z-=pz[j];
}
}
if(qn<dest)puts("-1");
else printf("%d",d[qx[qn-1]][qy[qn-1]][qz[qn-1]]-1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
20416 KB |
Output is correct |
2 |
Correct |
1 ms |
20416 KB |
Output is correct |
3 |
Correct |
0 ms |
20416 KB |
Output is correct |
4 |
Correct |
1 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
20416 KB |
Output is correct |
2 |
Correct |
4 ms |
20416 KB |
Output is correct |
3 |
Correct |
2 ms |
20416 KB |
Output is correct |
4 |
Correct |
1 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
20416 KB |
Output is correct |
2 |
Correct |
0 ms |
20416 KB |
Output is correct |
3 |
Correct |
1 ms |
20416 KB |
Output is correct |
4 |
Correct |
0 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
20416 KB |
Output is correct |
2 |
Correct |
19 ms |
20416 KB |
Output is correct |
3 |
Correct |
31 ms |
20416 KB |
Output is correct |
4 |
Correct |
43 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
20416 KB |
Output is correct |
2 |
Correct |
4 ms |
20416 KB |
Output is correct |
3 |
Correct |
29 ms |
20416 KB |
Output is correct |
4 |
Correct |
6 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
20416 KB |
Output is correct |
2 |
Correct |
23 ms |
20416 KB |
Output is correct |
3 |
Correct |
36 ms |
20416 KB |
Output is correct |
4 |
Correct |
12 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
20416 KB |
Output is correct |
2 |
Correct |
41 ms |
20416 KB |
Output is correct |
3 |
Correct |
104 ms |
20416 KB |
Output is correct |
4 |
Correct |
14 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
20416 KB |
Output is correct |
2 |
Correct |
111 ms |
20416 KB |
Output is correct |
3 |
Correct |
87 ms |
20416 KB |
Output is correct |
4 |
Correct |
120 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
20416 KB |
Output is correct |
2 |
Correct |
140 ms |
20416 KB |
Output is correct |
3 |
Correct |
144 ms |
20416 KB |
Output is correct |
4 |
Correct |
128 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
20416 KB |
Output is correct |
2 |
Correct |
59 ms |
20416 KB |
Output is correct |
3 |
Correct |
180 ms |
20416 KB |
Output is correct |
4 |
Correct |
52 ms |
20416 KB |
Output is correct |