Submission #1109370

#TimeUsernameProblemLanguageResultExecution timeMemory
1109370classicTracks in the Snow (BOI13_tracks)C++17
100 / 100
464 ms111960 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...