This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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::deque<std::pair<int, int>> deque;
std::vector<std::vector<int>> depth(numRow, std::vector<int>(numColumn));
deque.emplace_back(0, 0);
depth[0][0] = 1;
int result = 1;
while (!deque.empty()) {
auto [currentRow, currentColumn] = deque.front();
deque.pop_front();
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 &&
snow[nextRow][nextColumn] != '.' && depth[nextRow][nextColumn] == 0) {
if (snow[currentRow][currentColumn] == snow[nextRow][nextColumn]) {
depth[nextRow][nextColumn] = depth[currentRow][currentColumn];
deque.emplace_front(nextRow, nextColumn);
} else {
depth[nextRow][nextColumn] = depth[currentRow][currentColumn] + 1;
deque.emplace_back(nextRow, nextColumn);
}
}
}
}
std::cout << result;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |