Submission #517770

# Submission time Handle Problem Language Result Execution time Memory
517770 2022-01-23T07:24:20 Z Jomnoi Tracks in the Snow (BOI13_tracks) C++17
100 / 100
523 ms 126476 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int N = 4e3 + 10;
const int INF = 1e9 + 7;
const int r[] = {-1, 0, 1, 0};
const int c[] = {0, -1, 0, 1};

char a[N][N];
int dist[N][N];

int main() {
	cin.tie(0)->sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++) {
        cin >> (a[i] + 1);
    }

	int ans = 0;
	deque <pair <int, int>> dq;
	dq.emplace_back(1, 1);
	dist[1][1] = 1;
	while(!dq.empty()) {
		auto [xi, yi] = dq.front();
		dq.pop_front();

		ans = max(ans, dist[xi][yi]);
		for(int d = 0; d < 4; d++) {
			int xj = xi + r[d], yj = yi + c[d];
			if(xj < 1 or xj > h or yj < 1 or yj > w or a[xj][yj] == '.') {
				continue;
			}

			int w = (a[xi][yi] != a[xj][yj]);
			if(dist[xj][yj] == 0) {
				dist[xj][yj] = dist[xi][yi] + w;
				if(w == 1) {
					dq.emplace_back(xj, yj);
				}
				else {
					dq.emplace_front(xj, yj);
				}
			}
		}
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5496 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 6 ms 5188 KB Output is correct
5 Correct 3 ms 2880 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 700 KB Output is correct
8 Correct 2 ms 708 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 3 ms 2520 KB Output is correct
11 Correct 3 ms 2108 KB Output is correct
12 Correct 5 ms 3016 KB Output is correct
13 Correct 4 ms 2888 KB Output is correct
14 Correct 3 ms 2860 KB Output is correct
15 Correct 12 ms 5284 KB Output is correct
16 Correct 15 ms 5400 KB Output is correct
17 Correct 8 ms 5220 KB Output is correct
18 Correct 6 ms 5124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 30852 KB Output is correct
2 Correct 44 ms 15052 KB Output is correct
3 Correct 145 ms 65268 KB Output is correct
4 Correct 70 ms 32636 KB Output is correct
5 Correct 97 ms 53264 KB Output is correct
6 Correct 473 ms 99128 KB Output is correct
7 Correct 19 ms 32164 KB Output is correct
8 Correct 16 ms 30784 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 19 ms 31548 KB Output is correct
12 Correct 1 ms 1612 KB Output is correct
13 Correct 32 ms 15152 KB Output is correct
14 Correct 20 ms 10344 KB Output is correct
15 Correct 21 ms 13012 KB Output is correct
16 Correct 37 ms 5716 KB Output is correct
17 Correct 88 ms 28768 KB Output is correct
18 Correct 61 ms 35716 KB Output is correct
19 Correct 52 ms 32692 KB Output is correct
20 Correct 39 ms 25516 KB Output is correct
21 Correct 110 ms 51208 KB Output is correct
22 Correct 100 ms 52264 KB Output is correct
23 Correct 176 ms 43520 KB Output is correct
24 Correct 94 ms 48572 KB Output is correct
25 Correct 264 ms 85260 KB Output is correct
26 Correct 305 ms 126476 KB Output is correct
27 Correct 509 ms 115004 KB Output is correct
28 Correct 477 ms 99940 KB Output is correct
29 Correct 449 ms 100040 KB Output is correct
30 Correct 523 ms 104540 KB Output is correct
31 Correct 466 ms 71608 KB Output is correct
32 Correct 376 ms 102336 KB Output is correct