Submission #389922

#TimeUsernameProblemLanguageResultExecution timeMemory
389922null_aweTracks in the Snow (BOI13_tracks)C++14
100 / 100
947 ms112080 KiB
#include <bits/stdc++.h> using namespace std; vector<int> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1}; int main() { int h, w; cin >> h >> w; vector<string> field(h); vector<vector<int>> rank(h, vector<int>(w, 0)); for (int i = 0; i < h; ++i) cin >> field[i]; int m = 1; rank[0][0] = 1; deque<pair<int, int>> q; q.push_back({0, 0}); while (!q.empty()) { pair<int, int> s = q.front(); m = max(m, rank[s.first][s.second]); q.pop_front(); for (int i = 0; i < 4; ++i) { int x = s.first + dx[i], y = s.second + dy[i]; if (x < 0 || y < 0 || x >= h || y >= w || rank[x][y] > 0 || field[x][y] == '.') continue; int r = rank[s.first][s.second]; if (field[s.first][s.second] == field[x][y]) { q.push_front({x, y}); rank[x][y] = r; } else { q.push_back({x, y}); rank[x][y] = r + 1; } } } cout << m; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...