Submission #1832

#TimeUsernameProblemLanguageResultExecution timeMemory
1832alephnull토마토 (KOI13_tomato)C++98
16 / 16
132 ms5284 KiB
#include <cstdio> #include <queue> #include <utility> using namespace std; int main(){ int m,n;scanf("%d %d",&m,&n); int table[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&table[i][j]); queue<pair<pair<int,int>,int> > q; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(table[i][j]==1) q.push(make_pair(make_pair(i,j),0)); int ans=0; while(!q.empty()){ int y=q.front().first.first; int x=q.front().first.second; int level=q.front().second; int dy[4]={1,0,0,-1}; int dx[4]={0,-1,1,0}; if(level>ans)ans=level; for(int i=0;i<4;i++){ int yy=y+dy[i]; int xx=x+dx[i]; if(yy<n&&yy>=0&&xx<m&&xx>=0) if(table[yy][xx]==0){ table[yy][xx]=1; q.push(make_pair(make_pair(yy,xx),level+1)); //printf("%d %d\n",yy,xx); } } q.pop(); } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(table[i][j]==0)ans=-1; } } printf("%d",ans); }
#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...