#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() {
iostream::sync_with_stdio(false);
cin.tie(0);
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.size()) {
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 |
16 ms |
3580 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
7 ms |
3276 KB |
Output is correct |
5 |
Correct |
3 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
772 KB |
Output is correct |
10 |
Correct |
2 ms |
1612 KB |
Output is correct |
11 |
Correct |
3 ms |
1484 KB |
Output is correct |
12 |
Correct |
5 ms |
1948 KB |
Output is correct |
13 |
Correct |
3 ms |
1868 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
10 ms |
3484 KB |
Output is correct |
16 |
Correct |
12 ms |
3532 KB |
Output is correct |
17 |
Correct |
8 ms |
3404 KB |
Output is correct |
18 |
Correct |
8 ms |
3312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
15820 KB |
Output is correct |
2 |
Correct |
37 ms |
10248 KB |
Output is correct |
3 |
Correct |
189 ms |
59644 KB |
Output is correct |
4 |
Correct |
67 ms |
25680 KB |
Output is correct |
5 |
Correct |
161 ms |
42752 KB |
Output is correct |
6 |
Correct |
586 ms |
94252 KB |
Output is correct |
7 |
Correct |
13 ms |
16460 KB |
Output is correct |
8 |
Correct |
10 ms |
15836 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
11 ms |
16204 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
39 ms |
10244 KB |
Output is correct |
14 |
Correct |
24 ms |
7056 KB |
Output is correct |
15 |
Correct |
25 ms |
9292 KB |
Output is correct |
16 |
Correct |
23 ms |
4296 KB |
Output is correct |
17 |
Correct |
97 ms |
21244 KB |
Output is correct |
18 |
Correct |
79 ms |
28204 KB |
Output is correct |
19 |
Correct |
64 ms |
25668 KB |
Output is correct |
20 |
Correct |
59 ms |
19100 KB |
Output is correct |
21 |
Correct |
119 ms |
41488 KB |
Output is correct |
22 |
Correct |
163 ms |
42820 KB |
Output is correct |
23 |
Correct |
192 ms |
34616 KB |
Output is correct |
24 |
Correct |
124 ms |
38724 KB |
Output is correct |
25 |
Correct |
405 ms |
80752 KB |
Output is correct |
26 |
Correct |
355 ms |
118676 KB |
Output is correct |
27 |
Correct |
511 ms |
107268 KB |
Output is correct |
28 |
Correct |
619 ms |
94464 KB |
Output is correct |
29 |
Correct |
591 ms |
92648 KB |
Output is correct |
30 |
Correct |
536 ms |
97056 KB |
Output is correct |
31 |
Correct |
553 ms |
61932 KB |
Output is correct |
32 |
Correct |
406 ms |
92528 KB |
Output is correct |