Submission #17092

#TimeUsernameProblemLanguageResultExecution timeMemory
17092hjk0553토마토 (KOI13_tomato)C++98
3.20 / 16
129 ms5840 KiB
#include<bits/stdc++.h> struct point { int x; int y; }; int t[1010][1010]; int n,mm,ans; int main() { std::queue <point> q; point m,l; scanf("%d %d",&n,&mm); for(int i=1;i<=n;i++) { for(int j=1;j<=mm;j++) { scanf("%d",&t[i][j]); if(t[i][j]==1) { m.x=i,m.y=j; q.push({m.x,m.y}); } } } while(!q.empty()) { l=q.front(); q.pop(); if(t[l.x-1][l.y]==0&&l.x-1>0) t[l.x-1][l.y]=t[l.x][l.y]+1,q.push({l.x-1,l.y}); //왼쪽 push if(t[l.x+1][l.y]==0&&l.x+1<=n) t[l.x+1][l.y]=t[l.x][l.y]+1,q.push({l.x+1,l.y}); //오른쪽 push if(t[l.x][l.y-1]==0&&l.y-1>0) t[l.x][l.y-1]=t[l.x][l.y]+1,q.push({l.x,l.y-1}); //위쪽 push if(t[l.x][l.y+1]==0&&l.y+1<=mm) t[l.x][l.y+1]=t[l.x][l.y]+1,q.push({l.x,l.y+1}); //아래쪽 push } for(int i=1;i<=n;i++) for(int j=1;j<=mm;j++) if(t[i][j]==0) {printf("-1");return 0;} else if(t[i][j]>ans) ans=t[i][j]; printf("%d",ans-1); 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...