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>
#define m(a,b) std::make_pair(a,b)
typedef std::pair<int,int> P1;
typedef std::pair<P1,int> P2;
typedef std::queue<P2> Q;
Q q;
int arr[100][100][100];
int dx[6]={1,0,0,-1,0,0};
int dy[6]={0,1,0,0,-1,0};
int dz[6]={0,0,1,0,0,-1};
int main()
{
int s=0,c=0,p=0,d=0,m,n,h,nx,ny,nz,i,j,k;
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",&arr[i][j][k]);
for(i=0;i<h;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<m;k++)
{
if(arr[i][j][k]==1)
{
q.push(m(m(i,j),k));
p++;
}
if(arr[i][j][k]==0)
s++;
}
}
}
while(!q.empty())
{
for(i=0;i<6;i++)
{
nx=q.front().first.first+dx[i];
ny=q.front().first.second+dy[i];
nz=q.front().second+dz[i];
if(0<=nx&&nx<h&&0<=ny&&ny<n&&0<=nz&&nz<m&&arr[nx][ny][nz]==0)
{
arr[nx][ny][nz]=1;
q.push(m(m(nx,ny),nz));
c++;
s--;
}
}
q.pop();
p--;
if(p==0)
{
if(c!=0)
d++;
p=c;
c=0;
}
}
if(s!=0)
printf("-1");
else
printf("%d",d);
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... |