Submission #730031

#TimeUsernameProblemLanguageResultExecution timeMemory
730031roadsterTracks in the Snow (BOI13_tracks)C++17
100 / 100
600 ms138816 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; #define pb push_back #define sz(x) (int)(x).size() #define f first #define s second #define mp make_pair const int INF = INT_MAX; const int MOD = 1e9 + 7; const int hmx = 4005, wmx = 4005; int h, w, ans = 1; vector<string> grid(hmx); vector<vi> depth(hmx, vi (wmx)); int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0}; bool is_valid(int r, int c) { return r >= 0 && r < h && c >= 0 && c < w && grid[r][c] != '.'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> h >> w; for (int i = 0; i < h; i++) cin >> grid[i]; deque<pair<int, int>> dq; dq.push_front({0, 0}); depth[0][0] = 1; while (!dq.empty()) { auto nxt = dq.front(); dq.pop_front(); ans = max(ans, depth[nxt.f][nxt.s]); for (int i = 0; i < 4; i++) { int x = nxt.f + dx[i], y = nxt.s + dy[i]; if (is_valid(x, y) && depth[x][y] == 0) { if (grid[x][y] == grid[nxt.f][nxt.s]) { depth[x][y] = depth[nxt.f][nxt.s]; dq.push_front({x, y}); } else { depth[x][y] = depth[nxt.f][nxt.s] + 1; dq.push_back({x, y}); } } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...