Submission #12849

# Submission time Handle Problem Language Result Execution time Memory
12849 2015-01-10T02:28:50 Z yongwhan 토마토 (KOI13_tomato) C++
0 / 16
44 ms 2652 KB
#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 time Memory Grader output
1 Incorrect 0 ms 1668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -