답안 #1024417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024417 2024-07-16T04:13:04 Z _unknown_2010 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
383 ms 130872 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;
}
/*
RRRRR
.F..R
.F..R
.F..R
.FFFR
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3940 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 5 ms 3644 KB Output is correct
5 Correct 2 ms 2140 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 848 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 2 ms 1628 KB Output is correct
12 Correct 4 ms 2140 KB Output is correct
13 Correct 2 ms 2140 KB Output is correct
14 Correct 2 ms 2000 KB Output is correct
15 Correct 7 ms 3668 KB Output is correct
16 Correct 9 ms 3788 KB Output is correct
17 Correct 7 ms 3676 KB Output is correct
18 Correct 5 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15964 KB Output is correct
2 Correct 28 ms 11964 KB Output is correct
3 Correct 144 ms 75344 KB Output is correct
4 Correct 44 ms 29564 KB Output is correct
5 Correct 112 ms 51792 KB Output is correct
6 Correct 369 ms 109888 KB Output is correct
7 Correct 7 ms 16728 KB Output is correct
8 Correct 6 ms 15964 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 7 ms 16220 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 25 ms 11860 KB Output is correct
14 Correct 19 ms 8024 KB Output is correct
15 Correct 11 ms 10332 KB Output is correct
16 Correct 16 ms 5100 KB Output is correct
17 Correct 68 ms 25212 KB Output is correct
18 Correct 48 ms 32080 KB Output is correct
19 Correct 41 ms 29384 KB Output is correct
20 Correct 34 ms 22572 KB Output is correct
21 Correct 87 ms 50700 KB Output is correct
22 Correct 112 ms 51536 KB Output is correct
23 Correct 131 ms 42520 KB Output is correct
24 Correct 84 ms 47696 KB Output is correct
25 Correct 201 ms 96336 KB Output is correct
26 Correct 212 ms 130872 KB Output is correct
27 Correct 272 ms 123064 KB Output is correct
28 Correct 383 ms 109800 KB Output is correct
29 Correct 380 ms 108232 KB Output is correct
30 Correct 326 ms 112424 KB Output is correct
31 Correct 323 ms 72016 KB Output is correct
32 Correct 253 ms 108344 KB Output is correct