Submission #839797

#TimeUsernameProblemLanguageResultExecution timeMemory
839797KavelmydexTracks in the Snow (BOI13_tracks)C++17
100 / 100
663 ms180704 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector <ll> vi; typedef pair <ll,ll> pi; #define f first #define s second int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1}; string grid[4000]; int depth[4000][4000], ans = 1; int n, m; bool inside(int x, int y){ return x >= 0 && y >= 0 && x < n && y < m && grid[x][y] != '.'; } int main() { //ios::sync_with_stdio(0); cin.tie(0); //freopen("guard.in", "r", stdin); //freopen("guard.out", "w", stdout); cin >> n >> m; for(int i=0; i<n; i++){ cin >> grid[i]; } deque <pi> q; q.push_back({0, 0}); depth[0][0] = 1; while(q.size()){ int u = q.front().f, v = q.front().s; ans = max(ans, depth[u][v]); q.pop_front(); for(int i=0; i<4; i++){ int x = u + dx[i], y = v + dy[i]; if(!inside(x, y) || depth[x][y] != 0) continue; if(grid[u][v] == grid[x][y]){ depth[x][y] = depth[u][v]; q.push_front({x, y}); }else{ depth[x][y] = depth[u][v] + 1; q.push_back({x, y}); } } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...