This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |