Submission #1009837

# Submission time Handle Problem Language Result Execution time Memory
1009837 2024-06-28T06:30:07 Z athiest07 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
435 ms 130904 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;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3988 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 4 ms 3420 KB Output is correct
5 Correct 3 ms 2140 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 3 ms 1672 KB Output is correct
12 Correct 6 ms 2284 KB Output is correct
13 Correct 3 ms 2136 KB Output is correct
14 Correct 2 ms 2140 KB Output is correct
15 Correct 7 ms 3676 KB Output is correct
16 Correct 13 ms 3932 KB Output is correct
17 Correct 6 ms 3676 KB Output is correct
18 Correct 4 ms 3656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16004 KB Output is correct
2 Correct 25 ms 11884 KB Output is correct
3 Correct 155 ms 75468 KB Output is correct
4 Correct 46 ms 29396 KB Output is correct
5 Correct 112 ms 51784 KB Output is correct
6 Correct 427 ms 109928 KB Output is correct
7 Correct 8 ms 16508 KB Output is correct
8 Correct 7 ms 15832 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 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 27 ms 11852 KB Output is correct
14 Correct 18 ms 7888 KB Output is correct
15 Correct 15 ms 10332 KB Output is correct
16 Correct 13 ms 4956 KB Output is correct
17 Correct 75 ms 25240 KB Output is correct
18 Correct 46 ms 32220 KB Output is correct
19 Correct 44 ms 29440 KB Output is correct
20 Correct 45 ms 22492 KB Output is correct
21 Correct 83 ms 50560 KB Output is correct
22 Correct 110 ms 51792 KB Output is correct
23 Correct 134 ms 42148 KB Output is correct
24 Correct 99 ms 47732 KB Output is correct
25 Correct 187 ms 96340 KB Output is correct
26 Correct 231 ms 130904 KB Output is correct
27 Correct 297 ms 122984 KB Output is correct
28 Correct 392 ms 109804 KB Output is correct
29 Correct 435 ms 108308 KB Output is correct
30 Correct 403 ms 112392 KB Output is correct
31 Correct 368 ms 72188 KB Output is correct
32 Correct 256 ms 108260 KB Output is correct