Submission #564940

# Submission time Handle Problem Language Result Execution time Memory
564940 2022-05-20T04:00:00 Z Garguy22 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
745 ms 131072 KB
#include <iostream>
#include <queue>
using namespace std;

typedef pair<int, int> pii;
#define mp make_pair
#define ff first
#define ss second

int n, m;
char grid[4007][4007];
int depth[4007][4007];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

bool chk(int x, int y) {
	return (x > -1 && x < n && y > -1 && y < m && grid[x][y] != '.');
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++)
			cin >> grid[i][j];
	}
	int ans = 1;
	deque<pii> q;
	q.push_back(mp(0, 0));
	depth[0][0] = 1;
	while(q.size()){
		pii u = q.front();
		q.pop_front();
		ans = max(ans, depth[u.ff][u.ss]);
		for(int i = 0; i < 4; i++){
			int x = u.ff + dx[i], y = u.ss + dy[i];
			if(chk(x, y) && depth[x][y] == 0){
				if(grid[x][y] == grid[u.ff][u.ss]){
					depth[x][y] = depth[u.ff][u.ss];
					q.push_front(mp(x, y));
				}else{
					depth[x][y] = depth[u.ff][u.ss] + 1;
					q.push_back(mp(x, y));
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5536 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 9 ms 5076 KB Output is correct
5 Correct 4 ms 2900 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 4 ms 2516 KB Output is correct
11 Correct 3 ms 2132 KB Output is correct
12 Correct 7 ms 3080 KB Output is correct
13 Correct 4 ms 2952 KB Output is correct
14 Correct 3 ms 2880 KB Output is correct
15 Correct 12 ms 5252 KB Output is correct
16 Correct 15 ms 5324 KB Output is correct
17 Correct 12 ms 5196 KB Output is correct
18 Correct 10 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 30772 KB Output is correct
2 Correct 52 ms 14984 KB Output is correct
3 Correct 384 ms 73352 KB Output is correct
4 Correct 100 ms 32588 KB Output is correct
5 Correct 248 ms 53408 KB Output is correct
6 Correct 705 ms 107836 KB Output is correct
7 Correct 18 ms 32212 KB Output is correct
8 Correct 16 ms 30800 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 16 ms 31572 KB Output is correct
12 Correct 2 ms 1592 KB Output is correct
13 Correct 55 ms 14992 KB Output is correct
14 Correct 39 ms 10356 KB Output is correct
15 Correct 38 ms 13084 KB Output is correct
16 Correct 23 ms 5696 KB Output is correct
17 Correct 129 ms 28672 KB Output is correct
18 Correct 111 ms 35600 KB Output is correct
19 Correct 106 ms 32644 KB Output is correct
20 Correct 107 ms 25608 KB Output is correct
21 Correct 219 ms 52696 KB Output is correct
22 Correct 278 ms 53320 KB Output is correct
23 Correct 257 ms 43736 KB Output is correct
24 Correct 242 ms 49760 KB Output is correct
25 Correct 503 ms 94356 KB Output is correct
26 Correct 468 ms 131072 KB Output is correct
27 Correct 595 ms 120948 KB Output is correct
28 Correct 745 ms 108068 KB Output is correct
29 Correct 709 ms 106396 KB Output is correct
30 Correct 674 ms 110424 KB Output is correct
31 Correct 530 ms 73456 KB Output is correct
32 Correct 552 ms 106172 KB Output is correct