Submission #791696

#TimeUsernameProblemLanguageResultExecution timeMemory
791696dwuyTracks in the Snow (BOI13_tracks)C++14
100 / 100
565 ms118860 KiB
/// (⌐■_■): "who's nvpu, dwuy?" /// dwuy : "revolym" #include <bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL) #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout) #define fi first #define se second #define endl "\n" #define len(s) int32_t(s.length()) #define MASK(k)(1LL<<(k)) #define TASK "" using namespace std; typedef tuple<int, int, int> tpiii; typedef pair<double, double> pdd; typedef pair<int, int> pii; typedef long long ll; const long long OO = 1e18; const int MOD = 1e9 + 7; const int INF = 1e9; const int MX = 4005; const int dx[] = {0, 0, -1, 1}; const int dy[] = {-1, 1, 0, 0}; int n, m; string a[MX]; int d[MX][MX]; void nhap(){ cin >> n >> m; for(int i=0; i<n; i++) cin >> a[i]; } void solve(){ deque<pii> Q; d[0][0] = 1; Q.push_front({0, 0}); int ans = 0; while(Q.size()){ int x, y; tie(x, y) = Q.front(); Q.pop_front(); ans = max(ans, d[x][y]); for(int i=0; i<4; i++){ int u = x + dx[i]; int v = y + dy[i]; if(u<0 || u>=n || v<0 || v>=m || d[u][v]!=0 || a[u][v]=='.') continue; if(a[u][v] == a[x][y]){ d[u][v] = d[x][y]; Q.push_front({u, v}); } else{ d[u][v] = d[x][y] + 1; Q.push_back({u, v}); } } } cout << ans; } int32_t main(){ fastIO; //file(TASK); nhap(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...