Submission #436316

# Submission time Handle Problem Language Result Execution time Memory
436316 2021-06-24T12:21:19 Z berserkK Tracks in the Snow (BOI13_tracks) C++17
100 / 100
705 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;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3784 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 1 ms 568 KB Output is correct
4 Correct 10 ms 3404 KB Output is correct
5 Correct 4 ms 1996 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 3 ms 1612 KB Output is correct
11 Correct 4 ms 1468 KB Output is correct
12 Correct 8 ms 2136 KB Output is correct
13 Correct 3 ms 1996 KB Output is correct
14 Correct 3 ms 1996 KB Output is correct
15 Correct 11 ms 3672 KB Output is correct
16 Correct 13 ms 3820 KB Output is correct
17 Correct 13 ms 3660 KB Output is correct
18 Correct 7 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15820 KB Output is correct
2 Correct 45 ms 11812 KB Output is correct
3 Correct 218 ms 75452 KB Output is correct
4 Correct 81 ms 29380 KB Output is correct
5 Correct 177 ms 51596 KB Output is correct
6 Correct 705 ms 109960 KB Output is correct
7 Correct 14 ms 16588 KB Output is correct
8 Correct 13 ms 15776 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 13 ms 16204 KB Output is correct
12 Correct 2 ms 1100 KB Output is correct
13 Correct 45 ms 11772 KB Output is correct
14 Correct 24 ms 8004 KB Output is correct
15 Correct 24 ms 10304 KB Output is correct
16 Correct 19 ms 4896 KB Output is correct
17 Correct 142 ms 25180 KB Output is correct
18 Correct 115 ms 32068 KB Output is correct
19 Correct 82 ms 29376 KB Output is correct
20 Correct 54 ms 22388 KB Output is correct
21 Correct 131 ms 50488 KB Output is correct
22 Correct 173 ms 51748 KB Output is correct
23 Correct 220 ms 42144 KB Output is correct
24 Correct 133 ms 47548 KB Output is correct
25 Correct 524 ms 96400 KB Output is correct
26 Correct 441 ms 130668 KB Output is correct
27 Correct 497 ms 122884 KB Output is correct
28 Correct 664 ms 110044 KB Output is correct
29 Correct 670 ms 108352 KB Output is correct
30 Correct 659 ms 112324 KB Output is correct
31 Correct 533 ms 72068 KB Output is correct
32 Correct 466 ms 108372 KB Output is correct