#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int MAXN = 4500;
char grid[MAXN][MAXN];
int dist[MAXN][MAXN];
int dX[] = {1, -1, 0, 0};
int dY[] = {0, 0, 1, -1};
int h, w;
int main(){
speedup
cin >> h >> w;
for (int i = 0; i < h; i++){
string s; cin >> s;
for (int j = 0; j < w; j++){
grid[i][j] = s[j];
}
}
deque<pair<int, int>> q;
q.push_back({0, 0});
for (int i = 0; i < MAXN; i++){
for (int j = 0; j < MAXN; j++){
dist[i][j] = 0;
}
}
dist[0][0] = 1;
int ans = 1;
while (!q.empty()){
auto &[x, y] = q.front(); q.pop_front();
ans = max(ans, dist[x][y]);
for (int i = 0; i < 4; i++){
int nX = x+dX[i], nY = y+dY[i];
if (nX >= 0 && nX < h && nY >= 0 && nY < w && grid[nX][nY] != '.' && dist[nX][nY] == 0){
if (grid[nX][nY] == grid[x][y]){
dist[nX][nY] = dist[x][y];
q.push_front({nX, nY});
}else{
dist[nX][nY] = dist[x][y]+1;
q.push_back({nX, nY});
}
}
}
}
cout << ans << endl;
return 0;
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:39:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
39 | auto &[x, y] = q.front(); q.pop_front();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
81748 KB |
Output isn't correct |
2 |
Correct |
30 ms |
79548 KB |
Output is correct |
3 |
Incorrect |
34 ms |
79752 KB |
Output isn't correct |
4 |
Incorrect |
34 ms |
81748 KB |
Output isn't correct |
5 |
Incorrect |
34 ms |
80716 KB |
Output isn't correct |
6 |
Correct |
28 ms |
79648 KB |
Output is correct |
7 |
Incorrect |
28 ms |
79784 KB |
Output isn't correct |
8 |
Incorrect |
29 ms |
79752 KB |
Output isn't correct |
9 |
Incorrect |
29 ms |
79956 KB |
Output isn't correct |
10 |
Incorrect |
30 ms |
80636 KB |
Output isn't correct |
11 |
Incorrect |
31 ms |
80596 KB |
Output isn't correct |
12 |
Incorrect |
32 ms |
80772 KB |
Output isn't correct |
13 |
Incorrect |
32 ms |
80848 KB |
Output isn't correct |
14 |
Incorrect |
36 ms |
80716 KB |
Output isn't correct |
15 |
Incorrect |
38 ms |
81736 KB |
Output isn't correct |
16 |
Incorrect |
38 ms |
81840 KB |
Output isn't correct |
17 |
Incorrect |
36 ms |
81584 KB |
Output isn't correct |
18 |
Incorrect |
35 ms |
81732 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
94880 KB |
Output is correct |
2 |
Incorrect |
55 ms |
85104 KB |
Output isn't correct |
3 |
Incorrect |
63 ms |
97100 KB |
Output isn't correct |
4 |
Incorrect |
71 ms |
87780 KB |
Output isn't correct |
5 |
Correct |
147 ms |
92788 KB |
Output is correct |
6 |
Runtime error |
630 ms |
213392 KB |
Execution killed with signal 11 |
7 |
Correct |
36 ms |
95580 KB |
Output is correct |
8 |
Correct |
35 ms |
94912 KB |
Output is correct |
9 |
Incorrect |
31 ms |
79576 KB |
Output isn't correct |
10 |
Correct |
30 ms |
79520 KB |
Output is correct |
11 |
Correct |
36 ms |
95304 KB |
Output is correct |
12 |
Correct |
30 ms |
80084 KB |
Output is correct |
13 |
Incorrect |
57 ms |
85100 KB |
Output isn't correct |
14 |
Incorrect |
46 ms |
83564 KB |
Output isn't correct |
15 |
Correct |
43 ms |
83908 KB |
Output is correct |
16 |
Incorrect |
44 ms |
81292 KB |
Output isn't correct |
17 |
Incorrect |
69 ms |
88404 KB |
Output isn't correct |
18 |
Correct |
83 ms |
88368 KB |
Output is correct |
19 |
Incorrect |
67 ms |
87904 KB |
Output isn't correct |
20 |
Incorrect |
40 ms |
87224 KB |
Output isn't correct |
21 |
Incorrect |
50 ms |
93172 KB |
Output isn't correct |
22 |
Correct |
140 ms |
92700 KB |
Output is correct |
23 |
Incorrect |
57 ms |
90612 KB |
Output isn't correct |
24 |
Correct |
121 ms |
93328 KB |
Output is correct |
25 |
Correct |
317 ms |
97220 KB |
Output is correct |
26 |
Correct |
424 ms |
145196 KB |
Output is correct |
27 |
Incorrect |
486 ms |
130596 KB |
Output isn't correct |
28 |
Runtime error |
619 ms |
213356 KB |
Execution killed with signal 11 |
29 |
Runtime error |
599 ms |
210088 KB |
Execution killed with signal 11 |
30 |
Runtime error |
608 ms |
222516 KB |
Execution killed with signal 11 |
31 |
Incorrect |
388 ms |
93852 KB |
Output isn't correct |
32 |
Runtime error |
494 ms |
219880 KB |
Execution killed with signal 11 |