Submission #12849

#TimeUsernameProblemLanguageResultExecution timeMemory
12849yongwhan토마토 (KOI13_tomato)C++98
0 / 16
44 ms2652 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; bool vis[n][m]; for (int i=0; i<n; i++) for (int j=0; j<m; j++) cin>>vis[i][j]; queue<ii> q; for (int i=0; i<n; i++) for (int j=0; j<m; j++) if(vis[i][j]) 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]) { vis[nxt.first][nxt.second]=true; 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]) { 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...