Submission #791687

#TimeUsernameProblemLanguageResultExecution timeMemory
791687dwuyTracks in the Snow (BOI13_tracks)C++14
41.25 / 100
678 ms235804 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 "" #define int long long 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[1][1] = 1; Q.push_front({1, 1}); 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...