Submission #807477

#TimeUsernameProblemLanguageResultExecution timeMemory
807477gtm7Tracks in the Snow (BOI13_tracks)C++17
82.50 / 100
2080 ms173012 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a[4000][4000]; bool visited[4000][4000]{false}; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int h, w; cin >> h >> w; char ch; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> ch; if (ch == 'F') a[i][j] = 1; else if (ch == 'R') a[i][j] = 2; else a[i][j] = 3; } } int ans = 1; set<vector<int>> q; vector<int> s; int ii, jj; q.insert({1, 0, 0}); visited[0][0] = true; while (!q.empty()) { s = *q.begin(); q.erase(q.begin()); for (int i = 0; i < 4; i++) { ii = s[1] + dx[i]; jj = s[2] + dy[i]; if (ii >= 0 && ii < h && jj >= 0 && jj < w && !visited[ii][jj] && a[ii][jj] != 3) { visited[ii][jj] = true; if (a[ii][jj] == a[s[1]][s[2]]) { q.insert({s[0], ii, jj}); } else { ans = max(ans, s[0] + 1); q.insert({s[0] + 1, ii, jj}); } } } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...