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