#include <bits/stdc++.h>
const std::vector<int> directionX{-1, 1, 0, 0};
const std::vector<int> directionY{0, 0, -1, 1};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int numRow, numColumn;
std::cin >> numRow >> numColumn;
std::vector<std::string> snow(numRow);
for (int row = 0; row < numRow; row++) {
std::cin >> snow[row];
}
std::queue<std::pair<int, int>> queue;
std::vector<std::vector<int>> depth(numRow, std::vector<int>(numColumn));
queue.emplace(0, 0);
depth[0][0] = 1;
int result = 1;
while (!queue.empty()) {
auto [currentRow, currentColumn] = queue.front();
queue.pop();
result = std::max(result, depth[currentRow][currentColumn]);
for (int direction = 0; direction < 4; direction++) {
int nextRow = currentRow + directionX[direction];
int nextColumn = currentColumn + directionY[direction];
if (nextRow >= 0 && nextRow < numRow && nextColumn >= 0 && nextColumn < numColumn && depth[nextRow][nextColumn] == 0) {
if (snow[currentRow][currentColumn] == snow[nextRow][nextColumn]) {
depth[nextRow][nextColumn] = depth[currentRow][currentColumn];
queue.emplace(nextRow, nextColumn);
} else {
depth[nextRow][nextColumn] = depth[currentRow][nextColumn] + 1;
queue.emplace(nextRow, nextColumn);
}
}
}
}
std::cout << result;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1872 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
1540 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
848 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
388 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
848 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
948 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
848 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
848 KB |
Output isn't correct |
15 |
Incorrect |
7 ms |
1872 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
1872 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
1752 KB |
Output isn't correct |
18 |
Incorrect |
5 ms |
1360 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
848 KB |
Output isn't correct |
2 |
Incorrect |
36 ms |
9824 KB |
Output isn't correct |
3 |
Incorrect |
476 ms |
93568 KB |
Output isn't correct |
4 |
Incorrect |
92 ms |
22088 KB |
Output isn't correct |
5 |
Incorrect |
198 ms |
52308 KB |
Output isn't correct |
6 |
Incorrect |
436 ms |
93248 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
848 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
840 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
848 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
592 KB |
Output isn't correct |
13 |
Incorrect |
37 ms |
9808 KB |
Output isn't correct |
14 |
Incorrect |
24 ms |
5712 KB |
Output isn't correct |
15 |
Incorrect |
31 ms |
6224 KB |
Output isn't correct |
16 |
Incorrect |
16 ms |
4176 KB |
Output isn't correct |
17 |
Incorrect |
104 ms |
24656 KB |
Output isn't correct |
18 |
Incorrect |
111 ms |
24268 KB |
Output isn't correct |
19 |
Incorrect |
100 ms |
22392 KB |
Output isn't correct |
20 |
Incorrect |
78 ms |
20552 KB |
Output isn't correct |
21 |
Incorrect |
229 ms |
54244 KB |
Output isn't correct |
22 |
Incorrect |
211 ms |
54132 KB |
Output isn't correct |
23 |
Incorrect |
232 ms |
44532 KB |
Output isn't correct |
24 |
Incorrect |
227 ms |
52808 KB |
Output isn't correct |
25 |
Incorrect |
478 ms |
93304 KB |
Output isn't correct |
26 |
Correct |
314 ms |
71092 KB |
Output is correct |
27 |
Incorrect |
439 ms |
93332 KB |
Output isn't correct |
28 |
Incorrect |
459 ms |
95176 KB |
Output isn't correct |
29 |
Incorrect |
464 ms |
93328 KB |
Output isn't correct |
30 |
Incorrect |
427 ms |
91140 KB |
Output isn't correct |
31 |
Incorrect |
307 ms |
59808 KB |
Output isn't correct |
32 |
Incorrect |
433 ms |
95412 KB |
Output isn't correct |