Submission #3144

#TimeUsernameProblemLanguageResultExecution timeMemory
3144club4208토마토 (KOI13_tomato)C++98
0 / 16
0 ms12812 KiB
#include <stdio.h> int dt[1001][1001], level[1001][1001]; int m, n; short queueX[1000001], queueY[1000001]; int dx[4]={-1, 1, 0, 0}; int dy[4]={0, 0, 1, -1}; int main(){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d %d", &m, &n); int i, j; int head=1, tail=0; int cnt=0; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d", &dt[i][j]); if(dt[i][j]==1){queueX[++tail]=i; queueY[tail]=j; level[i][j]=1;} if(dt[i][j]==0){cnt++;} } } bool check=false; while(head<=tail){ int curx, cury; curx=queueX[head]; cury=queueY[head]; head++; for(i=0;i<4;i++){ int ax, ay; ax=curx+dx[i]; ay=cury+dy[i]; if(dt[ax][ay]==0 && 1<=ax && ax<=n && 1<=ay && ay<=m){ dt[ax][ay]=1; queueX[++tail]=ax, queueY[tail]=ay; level[ax][ay]=level[curx][cury]+1; cnt--; if(cnt==0){printf("%d", level[ax][ay]-1); check=true;} } } } if(!check) printf("-1"); else return 0; 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...