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<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;
}
# | 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... |