답안 #140582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140582 2019-08-03T15:54:26 Z khrbuddy03 토마토 (KOI13_tomato) C++14
16 / 16
108 ms 7928 KB
#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';
}


# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 7 ms 1528 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1016 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 7 ms 2808 KB Output is correct
4 Correct 6 ms 2300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 6 ms 1400 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 6 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 3860 KB Output is correct
2 Correct 26 ms 5752 KB Output is correct
3 Correct 14 ms 2172 KB Output is correct
4 Correct 13 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 5528 KB Output is correct
2 Correct 41 ms 4728 KB Output is correct
3 Correct 8 ms 1276 KB Output is correct
4 Correct 9 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3064 KB Output is correct
2 Correct 81 ms 7000 KB Output is correct
3 Correct 12 ms 1272 KB Output is correct
4 Correct 53 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 7456 KB Output is correct
2 Correct 107 ms 7592 KB Output is correct
3 Correct 94 ms 7928 KB Output is correct
4 Correct 75 ms 6264 KB Output is correct