#include <bits/stdc++.h>
using namespace std;
const int N = 4000, x[4] = {0, 0, -1, 1}, y[4] = {-1, 1, 0, 0};
string t[N];
bitset<N> v[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w; cin >> h >> w;
for (int i = 0; i < h; i++) cin >> t[i];
int ans = 1;
struct node {
int r, c, d;
};
deque<node> bfs;
bfs.push_back({0, 0, 1});
while (!bfs.empty()) {
node n = bfs.front();
bfs.pop_front();
ans = max(ans, n.d);
for (int i = 0; i < 4; i++) {
int r = n.r + x[i], c = n.c + y[i];
if (r >= 0 && r < h && c >= 0 && c < w && !v[r][c] && t[r][c] != '.') {
if (t[r][c] == t[n.r][n.c])
bfs.push_front({r, c, n.d});
else
bfs.push_back({r, c, n.d + 1});
v[r][c] = 1;
}
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1368 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
4 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
6 ms |
1372 KB |
Output is correct |
16 |
Correct |
7 ms |
1372 KB |
Output is correct |
17 |
Correct |
5 ms |
1116 KB |
Output is correct |
18 |
Correct |
4 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
23 ms |
4188 KB |
Output is correct |
3 |
Correct |
122 ms |
35712 KB |
Output is correct |
4 |
Correct |
29 ms |
8948 KB |
Output is correct |
5 |
Correct |
98 ms |
20764 KB |
Output is correct |
6 |
Correct |
341 ms |
54804 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
24 ms |
4188 KB |
Output is correct |
14 |
Correct |
14 ms |
2652 KB |
Output is correct |
15 |
Correct |
8 ms |
2908 KB |
Output is correct |
16 |
Correct |
12 ms |
1884 KB |
Output is correct |
17 |
Correct |
59 ms |
10064 KB |
Output is correct |
18 |
Correct |
34 ms |
9944 KB |
Output is correct |
19 |
Correct |
29 ms |
9364 KB |
Output is correct |
20 |
Correct |
31 ms |
8272 KB |
Output is correct |
21 |
Correct |
78 ms |
21076 KB |
Output is correct |
22 |
Correct |
98 ms |
20564 KB |
Output is correct |
23 |
Correct |
118 ms |
17744 KB |
Output is correct |
24 |
Correct |
78 ms |
20564 KB |
Output is correct |
25 |
Correct |
192 ms |
35832 KB |
Output is correct |
26 |
Correct |
266 ms |
101728 KB |
Output is correct |
27 |
Correct |
278 ms |
65164 KB |
Output is correct |
28 |
Correct |
340 ms |
54720 KB |
Output is correct |
29 |
Correct |
349 ms |
53352 KB |
Output is correct |
30 |
Correct |
311 ms |
54608 KB |
Output is correct |
31 |
Correct |
302 ms |
23860 KB |
Output is correct |
32 |
Correct |
247 ms |
54796 KB |
Output is correct |