Submission #441343

# Submission time Handle Problem Language Result Execution time Memory
441343 2021-07-05T02:24:07 Z HadiHosseini Tracks in the Snow (BOI13_tracks) C++14
100 / 100
578 ms 118996 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 4000; 
const int M = 4000;
int n, m;
char a[N][M]; 
int d[N][M];
int ans = 1;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
 
bool inside(int r, int c) {
	if (r < 0 || r > n || c < 0 || c > m) return false;
	if (a[r][c] == '.') return false;
	return true; 
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
 
 cin >> n >> m;
 for(int i = 0 ; i < n; i++){
 	string s; cin >> s;
 	for(int j = 0 ; j < m; j++){
 		 a[i][j] = s[j];
 	}
 }

 n--; m--;
 
 deque<pair<int, int>> q;
 q.push_back({0, 0});
 d[0][0] = 1;
 while(!q.empty()){
 	auto node = q.front();
 	q.pop_front();
 	ans = max(ans, d[node.first][node.second]);
 	for(int i = 0 ; i < 4; i++){
 	 int x = node.first + dx[i]; int y = node.second + dy[i];
 	 if(inside(x, y) && d[x][y] == 0){
 	   if(a[node.first][node.second] == a[x][y]){
 	   	d[x][y] = d[node.first][node.second];
 	   	q.push_front({x, y});
 	   }
 	   else {
 	   	d[x][y] = d[node.first][node.second] + 1;
 	   	q.push_back({x, y});
 	   }
 	 }
 	}
 }
 
 cout << ans << "\n";
 
 
 
	return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 12 ms 5196 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 8 ms 4940 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 3 ms 2344 KB Output is correct
11 Correct 3 ms 2124 KB Output is correct
12 Correct 5 ms 3020 KB Output is correct
13 Correct 3 ms 2764 KB Output is correct
14 Correct 3 ms 2764 KB Output is correct
15 Correct 10 ms 4976 KB Output is correct
16 Correct 14 ms 5284 KB Output is correct
17 Correct 9 ms 4940 KB Output is correct
18 Correct 8 ms 5004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 30972 KB Output is correct
2 Correct 45 ms 13508 KB Output is correct
3 Correct 185 ms 57836 KB Output is correct
4 Correct 72 ms 28972 KB Output is correct
5 Correct 157 ms 44484 KB Output is correct
6 Correct 578 ms 92132 KB Output is correct
7 Correct 20 ms 32520 KB Output is correct
8 Correct 19 ms 30844 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 19 ms 31536 KB Output is correct
12 Correct 2 ms 1612 KB Output is correct
13 Correct 41 ms 13548 KB Output is correct
14 Correct 23 ms 9592 KB Output is correct
15 Correct 24 ms 12108 KB Output is correct
16 Correct 18 ms 5068 KB Output is correct
17 Correct 104 ms 24772 KB Output is correct
18 Correct 91 ms 31956 KB Output is correct
19 Correct 73 ms 29064 KB Output is correct
20 Correct 49 ms 22064 KB Output is correct
21 Correct 120 ms 43756 KB Output is correct
22 Correct 158 ms 44388 KB Output is correct
23 Correct 197 ms 36148 KB Output is correct
24 Correct 119 ms 40776 KB Output is correct
25 Correct 449 ms 78576 KB Output is correct
26 Correct 340 ms 118996 KB Output is correct
27 Correct 465 ms 105416 KB Output is correct
28 Correct 577 ms 92424 KB Output is correct
29 Correct 564 ms 90568 KB Output is correct
30 Correct 524 ms 94892 KB Output is correct
31 Correct 472 ms 63316 KB Output is correct
32 Correct 400 ms 90416 KB Output is correct