Submission #938836

# Submission time Handle Problem Language Result Execution time Memory
938836 2024-03-05T15:51:40 Z freedommo33 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
887 ms 123336 KB
#include <bits/stdc++.h>

using namespace std;
constexpr int M = 4005;
int kolor[M][M];
char tab[M][M];
int spojna[M*4];
int xx[4] = {0, 0, -1, 1};
int yy[4] = {1, -1, 0, 0};
int n, m;

bool isValid(int x, int y){
	if(1>x || x>n) return 0;
	if(1>y || y>m) return 0;
	if(tab[x][y]=='.') return 0;
	if(kolor[x][y]!=0) return 0;
	return 1;
}
int maks = 0;
void bfs(){
	queue<pair<int, int>> q;
	queue<pair<pair<int, int>, int>> next;
	q.push({1, 1});
	kolor[1][1] = 1;
	while(!q.empty() || !next.empty()){
		int aktWart = 1;
		if(q.empty()==1){
			pair<int, int> temp = next.front().first;
			kolor[temp.first][temp.second] = next.front().second;
			next.pop();
			q.push(temp);
		}
		pair<int, int> p = q.front();
		aktWart = kolor[p.first][p.second];
		maks = max(maks, aktWart);
		q.pop();
		for(int i=0; i<4; i++){
			int nx = xx[i] + p.first;
			int ny = yy[i] + p.second;
			if(isValid(nx, ny)){
				if(tab[nx][ny]==tab[p.first][p.second]){
					kolor[nx][ny] = aktWart;
					q.push({nx, ny});
				}
				else{
					next.push({{nx, ny}, kolor[p.first][p.second] + 1});
				}
			}
		}
	}
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			cin>>tab[i][j];
		}
	}
	bfs();
	cout<<maks<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 7504 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 9 ms 7368 KB Output is correct
5 Correct 4 ms 5720 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4688 KB Output is correct
10 Correct 3 ms 5468 KB Output is correct
11 Correct 3 ms 5468 KB Output is correct
12 Correct 8 ms 6076 KB Output is correct
13 Correct 3 ms 5724 KB Output is correct
14 Correct 3 ms 5724 KB Output is correct
15 Correct 20 ms 7260 KB Output is correct
16 Correct 21 ms 7728 KB Output is correct
17 Correct 12 ms 7260 KB Output is correct
18 Correct 10 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 32348 KB Output is correct
2 Correct 62 ms 18232 KB Output is correct
3 Correct 332 ms 73516 KB Output is correct
4 Correct 82 ms 35156 KB Output is correct
5 Correct 180 ms 55860 KB Output is correct
6 Correct 859 ms 123264 KB Output is correct
7 Correct 11 ms 32856 KB Output is correct
8 Correct 10 ms 32224 KB Output is correct
9 Correct 3 ms 2588 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 10 ms 32600 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 61 ms 18240 KB Output is correct
14 Correct 36 ms 12884 KB Output is correct
15 Correct 24 ms 15056 KB Output is correct
16 Correct 31 ms 8028 KB Output is correct
17 Correct 151 ms 31060 KB Output is correct
18 Correct 91 ms 37748 KB Output is correct
19 Correct 84 ms 35156 KB Output is correct
20 Correct 79 ms 28496 KB Output is correct
21 Correct 199 ms 54464 KB Output is correct
22 Correct 180 ms 55632 KB Output is correct
23 Correct 300 ms 45928 KB Output is correct
24 Correct 180 ms 51612 KB Output is correct
25 Correct 448 ms 94464 KB Output is correct
26 Correct 645 ms 83016 KB Output is correct
27 Correct 762 ms 97740 KB Output is correct
28 Correct 825 ms 123336 KB Output is correct
29 Correct 804 ms 122984 KB Output is correct
30 Correct 744 ms 116812 KB Output is correct
31 Correct 887 ms 77744 KB Output is correct
32 Correct 837 ms 97632 KB Output is correct