Submission #140582

#TimeUsernameProblemLanguageResultExecution timeMemory
140582khrbuddy03토마토 (KOI13_tomato)C++14
16 / 16
108 ms7928 KiB
#include <bits/stdc++.h> using namespace std; const int inf = 1009; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int b[inf][inf]; bool vis[inf][inf]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; swap(n, m); queue<pair<int, pair<int, int>>> q; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> b[i][j]; if (b[i][j] == 1) { q.push(make_pair(0, make_pair(i, j))); vis[i][j] = 1; } } int ans = 0; while (!q.empty()) { int dist = q.front().first; ans = max(ans, dist); pair<int, int> here = q.front().second; int y = here.first; int x = here.second; q.pop(); for (int i = 0; i < 4; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny >= n || ny < 0 || nx >= m || nx < 0 || vis[ny][nx] || b[ny][nx] == -1 || b[ny][nx] == 1) continue; vis[ny][nx] = true; q.push(make_pair(dist + 1, make_pair(ny, nx))); } } int ok = true; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (vis[i][j] || b[i][j] == -1) continue; ok = false; } } if (!ok) ans = -1; cout << ans << '\n'; }
#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...