#include <bits/stdc++.h>
using i64 = long long;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int h, w;
std::cin >> h >> w;
std::vector<std::string> g(h);
for (auto &s : g) {
std::cin >> s;
}
std::vector dis(h, std::vector<int>(w));
std::vector vis(h, std::vector<bool>(w));
dis[0][0] = 0;
std::deque<std::tuple<int, int>> q;
q.push_back({0, 0});
vis[0][0] = true;
int ans = 0;
while (q.size()) {
auto [x, y] = q.front();
q.pop_front();
ans = std::max(ans, dis[x][y]);
for (int i = 0; i < 4; i++) {
int tx = x + dx[i];
int ty = y + dy[i];
if (tx < 0 || tx >= h || ty < 0 || ty >= w || vis[tx][ty]) {
continue;
}
if (g[x][y] == g[tx][ty]) {
dis[tx][ty] = dis[x][y];
q.push_front({tx, ty});
} else {
dis[tx][ty] = dis[x][y] + 1;
q.push_back({tx, ty});
}
vis[tx][ty] = true;
}
}
std::cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2140 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
1672 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
860 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
15 |
Incorrect |
7 ms |
2180 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
1884 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
2024 KB |
Output isn't correct |
18 |
Incorrect |
4 ms |
1628 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
2 |
Incorrect |
34 ms |
13808 KB |
Output isn't correct |
3 |
Incorrect |
325 ms |
138576 KB |
Output isn't correct |
4 |
Incorrect |
89 ms |
23888 KB |
Output isn't correct |
5 |
Incorrect |
188 ms |
92680 KB |
Output isn't correct |
6 |
Incorrect |
433 ms |
113316 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
1368 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
1092 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
760 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
13 |
Incorrect |
36 ms |
13960 KB |
Output isn't correct |
14 |
Incorrect |
21 ms |
8284 KB |
Output isn't correct |
15 |
Incorrect |
22 ms |
8796 KB |
Output isn't correct |
16 |
Incorrect |
15 ms |
5724 KB |
Output isn't correct |
17 |
Incorrect |
110 ms |
34700 KB |
Output isn't correct |
18 |
Incorrect |
103 ms |
33896 KB |
Output isn't correct |
19 |
Incorrect |
98 ms |
24028 KB |
Output isn't correct |
20 |
Incorrect |
70 ms |
30408 KB |
Output isn't correct |
21 |
Incorrect |
211 ms |
84652 KB |
Output isn't correct |
22 |
Incorrect |
198 ms |
92724 KB |
Output isn't correct |
23 |
Incorrect |
163 ms |
66376 KB |
Output isn't correct |
24 |
Incorrect |
184 ms |
81148 KB |
Output isn't correct |
25 |
Incorrect |
459 ms |
136764 KB |
Output isn't correct |
26 |
Incorrect |
271 ms |
125796 KB |
Output isn't correct |
27 |
Incorrect |
329 ms |
128004 KB |
Output isn't correct |
28 |
Incorrect |
452 ms |
113324 KB |
Output isn't correct |
29 |
Incorrect |
433 ms |
109428 KB |
Output isn't correct |
30 |
Incorrect |
448 ms |
116548 KB |
Output isn't correct |
31 |
Incorrect |
343 ms |
63600 KB |
Output isn't correct |
32 |
Incorrect |
356 ms |
118544 KB |
Output isn't correct |