이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |