This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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++;
}
cout << ret << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |