답안 #777206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777206 2023-07-08T19:05:50 Z RonTheprogrammer Tracks in the Snow (BOI13_tracks) C++17
100 / 100
443 ms 130668 KB
#include <bits/stdc++.h>
using namespace std;

int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};

int n, m, depth[4000][4000], ans = 1;
string snow[4000];

bool inside(int x, int y) {
	return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}

int main() {
	iostream::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> snow[i];

	deque<pair<int, int>> q;
	q.push_back({0, 0});
	depth[0][0] = 1;

	while (q.size()) {
		pair<int, int> c = q.front();
		q.pop_front();
		ans = max(ans, depth[c.first][c.second]);

		for (int i = 0; i < 4; i++) {
			int x = c.first + dx[i], y = c.second + dy[i];
			if (inside(x, y) && depth[x][y] == 0) {
				if (snow[x][y] == snow[c.first][c.second]) {
					depth[x][y] = depth[c.first][c.second];
					q.push_front({x, y});
				} else {
					depth[x][y] = depth[c.first][c.second] + 1;
					q.push_back({x, y});
				}
			}
		}
	}

	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3796 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 5 ms 3412 KB Output is correct
5 Correct 2 ms 2004 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 712 KB Output is correct
9 Correct 1 ms 840 KB Output is correct
10 Correct 2 ms 1620 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 4 ms 2076 KB Output is correct
13 Correct 2 ms 2004 KB Output is correct
14 Correct 2 ms 2076 KB Output is correct
15 Correct 8 ms 3636 KB Output is correct
16 Correct 10 ms 3808 KB Output is correct
17 Correct 7 ms 3668 KB Output is correct
18 Correct 5 ms 3500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15828 KB Output is correct
2 Correct 29 ms 11792 KB Output is correct
3 Correct 148 ms 75316 KB Output is correct
4 Correct 47 ms 29268 KB Output is correct
5 Correct 123 ms 51572 KB Output is correct
6 Correct 414 ms 109896 KB Output is correct
7 Correct 9 ms 16596 KB Output is correct
8 Correct 9 ms 15828 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 14 ms 16212 KB Output is correct
12 Correct 1 ms 1104 KB Output is correct
13 Correct 35 ms 11856 KB Output is correct
14 Correct 17 ms 7884 KB Output is correct
15 Correct 13 ms 10296 KB Output is correct
16 Correct 14 ms 4900 KB Output is correct
17 Correct 73 ms 25308 KB Output is correct
18 Correct 53 ms 32104 KB Output is correct
19 Correct 46 ms 29372 KB Output is correct
20 Correct 39 ms 22372 KB Output is correct
21 Correct 91 ms 50508 KB Output is correct
22 Correct 115 ms 51576 KB Output is correct
23 Correct 145 ms 42228 KB Output is correct
24 Correct 91 ms 47484 KB Output is correct
25 Correct 293 ms 96252 KB Output is correct
26 Correct 258 ms 130668 KB Output is correct
27 Correct 314 ms 122836 KB Output is correct
28 Correct 443 ms 109824 KB Output is correct
29 Correct 413 ms 108332 KB Output is correct
30 Correct 367 ms 112304 KB Output is correct
31 Correct 348 ms 72008 KB Output is correct
32 Correct 287 ms 108168 KB Output is correct