#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
int h, w, ret = 1;
char tracks[4000][4000];
int depth[4000][4000];
bool inside(int x, int y) {
return (x > -1 && x < h && y > -1 && y < w && tracks[x][y] != '.');
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> h >> w;
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
cin >> tracks[r][c];
}
}
deque<pair<int,int>> q;
depth[0][0] = 1;
q.push_back({0,0});
while (!q.empty()) {
pair<int,int> c = q.front();
q.pop_front();
ret = max(ret, 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 (tracks[c.first][c.second] == tracks[x][y]) {
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 << ret;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7512 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
7 ms |
7512 KB |
Output is correct |
5 |
Correct |
3 ms |
3932 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2660 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
3 ms |
3676 KB |
Output is correct |
11 |
Correct |
2 ms |
3420 KB |
Output is correct |
12 |
Correct |
7 ms |
3932 KB |
Output is correct |
13 |
Correct |
3 ms |
3928 KB |
Output is correct |
14 |
Correct |
5 ms |
3928 KB |
Output is correct |
15 |
Correct |
11 ms |
7516 KB |
Output is correct |
16 |
Correct |
11 ms |
7516 KB |
Output is correct |
17 |
Correct |
8 ms |
7516 KB |
Output is correct |
18 |
Correct |
6 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
32256 KB |
Output is correct |
2 |
Correct |
38 ms |
16460 KB |
Output is correct |
3 |
Correct |
255 ms |
73556 KB |
Output is correct |
4 |
Correct |
70 ms |
35664 KB |
Output is correct |
5 |
Correct |
176 ms |
55816 KB |
Output is correct |
6 |
Correct |
557 ms |
107724 KB |
Output is correct |
7 |
Correct |
11 ms |
32860 KB |
Output is correct |
8 |
Correct |
11 ms |
32092 KB |
Output is correct |
9 |
Correct |
2 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
11 ms |
32604 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
38 ms |
16464 KB |
Output is correct |
14 |
Correct |
22 ms |
13148 KB |
Output is correct |
15 |
Correct |
20 ms |
15452 KB |
Output is correct |
16 |
Correct |
18 ms |
8264 KB |
Output is correct |
17 |
Correct |
92 ms |
31060 KB |
Output is correct |
18 |
Correct |
81 ms |
38072 KB |
Output is correct |
19 |
Correct |
70 ms |
35600 KB |
Output is correct |
20 |
Correct |
59 ms |
26964 KB |
Output is correct |
21 |
Correct |
149 ms |
54840 KB |
Output is correct |
22 |
Correct |
174 ms |
55872 KB |
Output is correct |
23 |
Correct |
176 ms |
46420 KB |
Output is correct |
24 |
Correct |
150 ms |
51764 KB |
Output is correct |
25 |
Correct |
431 ms |
94148 KB |
Output is correct |
26 |
Correct |
340 ms |
133732 KB |
Output is correct |
27 |
Correct |
424 ms |
121016 KB |
Output is correct |
28 |
Correct |
536 ms |
108244 KB |
Output is correct |
29 |
Correct |
553 ms |
106276 KB |
Output is correct |
30 |
Correct |
479 ms |
111408 KB |
Output is correct |
31 |
Correct |
394 ms |
75336 KB |
Output is correct |
32 |
Correct |
389 ms |
106108 KB |
Output is correct |