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>
struct data{
int x,y,z,lev;
}q[10000010];
int a[1010][1010],f,r,cnt;
int dy[]={-1,0,1,0},dz[]={0,1,0,-1};
int main(){
int j,k,m,n,ny,nz;
scanf("%d%d",&m,&n);
for(j=1;j<=n;++j){
for(k=1;k<=m;++k){
scanf("%d",&a[j][k]);
if(a[j][k]==1)q[++r].y=j,q[r].z=k;
if(!a[j][k])++cnt;
}
}
while(f<r){
++f;
for(j=0;j<4;++j){
ny=q[f].y+dy[j];
nz=q[f].z+dz[j];
if(ny<1||ny>n||nz<1||nz>m||a[ny][nz])continue;
q[++r].y=ny,q[r].z=nz,q[r].lev=q[f].lev+1;
a[ny][nz]=1;
--cnt;
}
if(!cnt)break;
}
if(cnt)printf("-1");
else printf("%d",q[r].lev);
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... |