Submission #988483

#TimeUsernameProblemLanguageResultExecution timeMemory
988483kflippyTracks in the Snow (BOI13_tracks)C++17
100 / 100
1087 ms125020 KiB
#include <bits/stdc++.h> using namespace std; int h, w; char s[4000][4000]; bool chk(pair<int, int> c) { return c.first > -1 && c.first < h && c.second < w && c.second > -1 && s[c.first][c.second] != '.'; } int main() { cin >> h >> w; deque<pair<int, int>> q; vector<vector<int>> d(h, vector<int>(w)); d[0][0] = 1; for(int i = 0; i < h; ++i) { for(int j = 0; j < w; ++j) { cin >> s[i][j]; } } q.push_front({0, 0}); vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1}; int ans = 0; while(!q.empty()) { pair<int, int> x = q.front(); q.pop_front(); ans = max(ans, d[x.first][x.second]); for(int i = 0; i < 4; ++i) { pair<int, int> y = {x.first + dx[i], x.second + dy[i]}; if(chk(y) && d[y.first][y.second] == 0) { if(s[y.first][y.second] == s[x.first][x.second]) { d[y.first][y.second] = d[x.first][x.second]; q.push_front({y.first, y.second}); } else { d[y.first][y.second] = d[x.first][x.second] + 1; q.push_back({y.first, y.second}); } } } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...