Submission #374229

#TimeUsernameProblemLanguageResultExecution timeMemory
374229daduamTracks in the Snow (BOI13_tracks)C++17
100 / 100
1582 ms111208 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<char>> meadow(n, vector<char>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> meadow[i][j]; } } vector<vector<int>> d(n, vector<int>(m)); deque<pair<int, int>> q; q.push_front({0, 0}); d[0][0] = 1; int rv = 0; while (!q.empty()) { auto [r, c] = q.front(); q.pop_front(); rv = max(rv, d[r][c]); static vector<pair<int, int>> dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; for (auto [x, y] : dirs) { x += r, y += c; if (x >= 0 && x < n && y >= 0 && y < m && !d[x][y] && meadow[x][y] != '.') { if (meadow[r][c] != meadow[x][y]) { d[x][y] = d[r][c] + 1; q.push_back({x, y}); } else { d[x][y] = d[r][c]; q.push_front({x, y}); } } } } cout << rv << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...