Submission #1049527

#TimeUsernameProblemLanguageResultExecution timeMemory
1049527inkvizytorTracks in the Snow (BOI13_tracks)C++17
86.88 / 100
1587 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int h, w; cin >> h >> w; vector<string> s (h); for (int i = 0; i < h; i++) { cin >> s[i]; } vector<vector<pair<int, bool>>> g (h*w); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '.') continue; if (i != 0 && s[i-1][j] != '.') { g[i*w+j].push_back({(i-1)*w+j, s[i][j]==s[i-1][j]}); } if (j != 0 && s[i][j-1] != '.') { g[i*w+j].push_back({i*w+j-1, s[i][j]==s[i][j-1]}); } if (i != h-1 && s[i+1][j] != '.') { g[i*w+j].push_back({(i+1)*w+j, s[i][j]==s[i+1][j]}); } if (j != w-1 && s[i][j+1] != '.') { g[i*w+j].push_back({i*w+j+1, s[i][j]==s[i][j+1]}); } } } deque<pair<int, int>> q; vector<bool> odw (h*w, 0); q.push_back({0, 1}); int maxd = 0; while (!q.empty()) { auto x = q.front(); q.pop_front(); if (odw[x.first]) { continue; } maxd = max(maxd, x.second); odw[x.first] = 1; for (auto i : g[x.first]) { if (odw[i.first]) continue; if (i.second) { q.push_front({i.first, x.second}); } else { q.push_back({i.first, x.second+1}); } } } cout << maxd << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...