#include <bits/stdc++.h>
using namespace std;
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
int n, m, depth[4000][4000], ans = 1;
string snow[4000];
bool inside(int x, int y) {
return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> snow[i];
deque<pair<int, int>> q;
q.push_back({0, 0});
depth[0][0] = 1;
while (!q.empty()) {
pair<int, int> c = q.front();
q.pop_front();
ans = max(ans, depth[c.first][c.second]);
for (int i = 0; i < 4; i++) {
int x = c.first + dx[i], y = c.second + dy[i];
if (inside(x,y) && depth[x][y] == 0) {
if (snow[x][y] == snow[c.first][c.second]) {
depth[x][y] = depth[c.first][c.second];
q.push_front({x,y});}
else {
depth[x][y] = depth[c.first][c.second] + 1;
q.push_back({x,y});
}
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4184 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
7 ms |
3676 KB |
Output is correct |
5 |
Correct |
3 ms |
2136 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
1880 KB |
Output is correct |
11 |
Correct |
3 ms |
1624 KB |
Output is correct |
12 |
Correct |
5 ms |
2140 KB |
Output is correct |
13 |
Correct |
3 ms |
2292 KB |
Output is correct |
14 |
Correct |
3 ms |
2136 KB |
Output is correct |
15 |
Correct |
10 ms |
3928 KB |
Output is correct |
16 |
Correct |
14 ms |
4188 KB |
Output is correct |
17 |
Correct |
11 ms |
3928 KB |
Output is correct |
18 |
Correct |
7 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15964 KB |
Output is correct |
2 |
Correct |
46 ms |
12624 KB |
Output is correct |
3 |
Correct |
329 ms |
87888 KB |
Output is correct |
4 |
Correct |
92 ms |
32596 KB |
Output is correct |
5 |
Correct |
225 ms |
53240 KB |
Output is correct |
6 |
Correct |
600 ms |
122456 KB |
Output is correct |
7 |
Correct |
9 ms |
16548 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
8 ms |
16216 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
45 ms |
12688 KB |
Output is correct |
14 |
Correct |
26 ms |
8796 KB |
Output is correct |
15 |
Correct |
24 ms |
11096 KB |
Output is correct |
16 |
Correct |
21 ms |
4944 KB |
Output is correct |
17 |
Correct |
118 ms |
28500 KB |
Output is correct |
18 |
Correct |
103 ms |
35412 KB |
Output is correct |
19 |
Correct |
92 ms |
32592 KB |
Output is correct |
20 |
Correct |
76 ms |
25452 KB |
Output is correct |
21 |
Correct |
194 ms |
52304 KB |
Output is correct |
22 |
Correct |
228 ms |
53528 KB |
Output is correct |
23 |
Correct |
226 ms |
43348 KB |
Output is correct |
24 |
Correct |
197 ms |
49632 KB |
Output is correct |
25 |
Correct |
472 ms |
108880 KB |
Output is correct |
26 |
Correct |
364 ms |
130628 KB |
Output is correct |
27 |
Correct |
488 ms |
135556 KB |
Output is correct |
28 |
Correct |
592 ms |
122684 KB |
Output is correct |
29 |
Correct |
589 ms |
120848 KB |
Output is correct |
30 |
Correct |
625 ms |
124292 KB |
Output is correct |
31 |
Correct |
454 ms |
73004 KB |
Output is correct |
32 |
Correct |
467 ms |
120780 KB |
Output is correct |