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>
#include<queue>
using namespace std;
int m,n,h,i,j,k,a[105][105][105],dx[6]{1,-1},dy[6]{0,0,1,-1},dz[6]{0,0,0,0,1,-1},mt;
struct zp{
int x,y,z;
}tempzp;
pair<zp,int>temppair;
queue<pair<zp,int> >q;
int main()
{
scanf("%d %d %d",&m,&n,&h);
for(i=0;i<h;i++)
for(j=0;j<n;j++)
for(k=0;k<m;k++)
scanf("%d",&a[i][j][k]);
for(i=0;i<h;i++)
for(j=0;j<n;j++)
for(k=0;k<m;k++)
if(a[i][j][k]==1){
tempzp.x=i;
tempzp.y=j;
tempzp.z=k;
q.push(make_pair(tempzp,0));
}
while(!q.empty()) {
temppair=q.front();
q.pop();
if(temppair.second>mt)mt=temppair.second;
for(i=0;i<6;i++) {
tempzp.x=temppair.first.x+dx[i];
tempzp.y=temppair.first.y+dy[i];
tempzp.z=temppair.first.z+dz[i];
if(tempzp.x<0||tempzp.y<0||tempzp.z<0||tempzp.x>=h||tempzp.y>=n||tempzp.z>=m||a[tempzp.x][tempzp.y][tempzp.z])continue;
a[tempzp.x][tempzp.y][tempzp.z]=1;
q.push(make_pair(tempzp,temppair.second+1));
}
}
for(i=0;i<h;i++)
for(j=0;j<n;j++)
for(k=0;k<m;k++)
if(!a[i][j][k]) {
puts("-1");
return 0;
}
printf("%d",mt);
}
# | 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... |