Submission #860696

# Submission time Handle Problem Language Result Execution time Memory
860696 2023-10-13T20:57:53 Z aroradev Tracks in the Snow (BOI13_tracks) C++17
100 / 100
645 ms 135452 KB
#include <bits/stdc++.h>
using namespace std;

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

int h, w;
vector<string> tracks;

bool inside(int x, int y) {
	return (x > -1 && x < h && y > -1 && y < w && tracks[x][y] != '.');
}

int main() {
	cin >> h >> w;
	tracks.resize(h);
	for (int i = 0; i < h; i++) {
		cin >> tracks[i];
	}
	
	deque<pair<int, int>> edges;
	vector<vector<int>> depth(h, vector<int>(w));
	
	edges.push_back({0, 0});
	depth[0][0] = 1;
	
	int ans = 0;
	while (!edges.empty()) {
		auto c = edges.front();
		edges.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) continue;
			
			if (tracks[x][y] == tracks[c.first][c.second]) {
				depth[x][y] = depth[c.first][c.second];
				edges.push_front({x, y});
			}
			else {
				depth[x][y] = depth[c.first][c.second] + 1;
				edges.push_back({x, y});
			}
		}
	}
	
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2184 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 1628 KB Output is correct
5 Correct 3 ms 856 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 4 ms 840 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 3 ms 1000 KB Output is correct
15 Correct 10 ms 2136 KB Output is correct
16 Correct 12 ms 2140 KB Output is correct
17 Correct 8 ms 1944 KB Output is correct
18 Correct 6 ms 1624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 45 ms 10344 KB Output is correct
3 Correct 355 ms 108916 KB Output is correct
4 Correct 87 ms 25940 KB Output is correct
5 Correct 221 ms 55980 KB Output is correct
6 Correct 626 ms 122632 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 45 ms 10332 KB Output is correct
14 Correct 27 ms 6488 KB Output is correct
15 Correct 23 ms 7256 KB Output is correct
16 Correct 21 ms 4380 KB Output is correct
17 Correct 120 ms 28008 KB Output is correct
18 Correct 98 ms 27676 KB Output is correct
19 Correct 88 ms 25936 KB Output is correct
20 Correct 98 ms 23892 KB Output is correct
21 Correct 202 ms 57772 KB Output is correct
22 Correct 221 ms 55812 KB Output is correct
23 Correct 233 ms 47756 KB Output is correct
24 Correct 201 ms 56844 KB Output is correct
25 Correct 497 ms 109092 KB Output is correct
26 Correct 411 ms 123968 KB Output is correct
27 Correct 533 ms 135452 KB Output is correct
28 Correct 645 ms 122632 KB Output is correct
29 Correct 630 ms 120992 KB Output is correct
30 Correct 593 ms 124900 KB Output is correct
31 Correct 451 ms 63056 KB Output is correct
32 Correct 525 ms 124364 KB Output is correct