Submission #517766

# Submission time Handle Problem Language Result Execution time Memory
517766 2022-01-23T07:21:25 Z Jomnoi Tracks in the Snow (BOI13_tracks) C++17
31.7708 / 100
2000 ms 94956 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++) {
		for(int j = 1; j <= w; j++) {
			dist[i][j] = INF;
		}
	}
    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[xi][yi] + w < dist[xj][yj]) {
				dist[xj][yj] = dist[xi][yi] + w;
				dq.emplace_back(xj, yj);
			}
		}
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 131 ms 5728 KB Output isn't correct
2 Correct 1 ms 464 KB Output is correct
3 Incorrect 1 ms 700 KB Output isn't correct
4 Incorrect 18 ms 4960 KB Output isn't correct
5 Incorrect 10 ms 3004 KB Output isn't correct
6 Correct 1 ms 444 KB Output is correct
7 Incorrect 1 ms 720 KB Output isn't correct
8 Incorrect 2 ms 712 KB Output isn't correct
9 Incorrect 1 ms 1104 KB Output isn't correct
10 Incorrect 5 ms 2504 KB Output isn't correct
11 Incorrect 3 ms 2124 KB Output isn't correct
12 Incorrect 27 ms 3020 KB Output isn't correct
13 Incorrect 12 ms 3036 KB Output isn't correct
14 Incorrect 10 ms 3008 KB Output isn't correct
15 Incorrect 61 ms 5532 KB Output isn't correct
16 Incorrect 156 ms 5452 KB Output isn't correct
17 Incorrect 95 ms 5264 KB Output isn't correct
18 Incorrect 20 ms 4884 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30924 KB Output is correct
2 Incorrect 394 ms 17924 KB Output isn't correct
3 Execution timed out 2103 ms 94528 KB Time limit exceeded
4 Incorrect 1616 ms 33860 KB Output isn't correct
5 Correct 122 ms 67984 KB Output is correct
6 Execution timed out 2043 ms 94956 KB Time limit exceeded
7 Correct 16 ms 32320 KB Output is correct
8 Correct 16 ms 30928 KB Output is correct
9 Incorrect 10 ms 584 KB Output isn't correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 18 ms 31696 KB Output is correct
12 Correct 1 ms 1616 KB Output is correct
13 Incorrect 402 ms 17876 KB Output isn't correct
14 Incorrect 178 ms 12000 KB Output isn't correct
15 Correct 25 ms 13000 KB Output is correct
16 Incorrect 331 ms 6696 KB Output isn't correct
17 Incorrect 1389 ms 36364 KB Output isn't correct
18 Correct 61 ms 35732 KB Output is correct
19 Incorrect 1581 ms 33756 KB Output isn't correct
20 Execution timed out 2095 ms 31104 KB Time limit exceeded
21 Execution timed out 2011 ms 70292 KB Time limit exceeded
22 Correct 135 ms 67892 KB Output is correct
23 Execution timed out 2007 ms 57220 KB Time limit exceeded
24 Correct 84 ms 69504 KB Output is correct
25 Correct 295 ms 94472 KB Output is correct
26 Correct 512 ms 80960 KB Output is correct
27 Incorrect 696 ms 94372 KB Output isn't correct
28 Execution timed out 2093 ms 94920 KB Time limit exceeded
29 Execution timed out 2087 ms 94824 KB Time limit exceeded
30 Execution timed out 2103 ms 93032 KB Time limit exceeded
31 Execution timed out 2072 ms 74120 KB Time limit exceeded
32 Execution timed out 2008 ms 94712 KB Time limit exceeded