Submission #468388

#TimeUsernameProblemLanguageResultExecution timeMemory
468388Dan4LifeTracks in the Snow (BOI13_tracks)C++17
100 / 100
642 ms235956 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n, m, depth[4001][4001]; int X[] = {1, -1, 0, 0}; int Y[] = {0, 0, 1, -1}; string a[4001]; bool inside(int i, int j) { if(i<0 or j<0 or i>=n or j>=m or a[i][j]=='.') return false; return true; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; depth[0][0]=1; deque<pair<int,int>> Q; Q.push_back({0,0}); int ans = 0; while(!Q.empty()) { auto s = Q.front(); Q.pop_front(); int x = s.first, y = s.second; ans = max(ans, depth[x][y]); for(int i = 0; i < 4; i++) { int nx = x+X[i], ny = y+Y[i]; if(inside(nx,ny) and depth[nx][ny]==0){ if(a[x][y]==a[nx][ny]){ depth[nx][ny]=depth[x][y]; Q.push_front({nx,ny}); } else{ depth[nx][ny]=1+depth[x][y]; Q.push_back({nx,ny}); } } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...