Submission #12850

#TimeUsernameProblemLanguageResultExecution timeMemory
12850yongwhan토마토 (KOI13_tomato)C++98
16 / 16
136 ms5716 KiB
#include<algorithm> #include<iostream> #include<queue> #include<utility> using namespace std; typedef pair<int,int> ii; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int m,n; cin>>m>>n; queue<ii> q; int vis[n][m]; for (int i=0; i<n; i++) for (int j=0; j<m; j++) { cin>>vis[i][j]; if(vis[i][j]==1) q.push(make_pair(i,j)); } int ret=0; while(!q.empty()) { int sz=q.size(); bool updated=false; while(sz--) { ii cur=q.front(); q.pop(); for (int di=-1; di<=1; di++) for (int dj=-1; dj<=1; dj++) if(abs(di)+abs(dj)==1) { ii nxt=cur; nxt.first+=di; nxt.second+=dj; if(0<=nxt.first && nxt.first<n && 0<=nxt.second && nxt.second<m) { if(vis[nxt.first][nxt.second]==0) { vis[nxt.first][nxt.second]=1; q.push(nxt); updated=true; } } } } if(updated) ret++; } for (int i=0; i<n; i++) for (int j=0; j<m; j++) if(vis[i][j]==0) { cout << -1 << endl; return 0; } cout << ret << endl; 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...