Submission #16233

#TimeUsernameProblemLanguageResultExecution timeMemory
16233eaststar토마토 (KOI13_tomato)C++14
16 / 16
98 ms161316 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...