Submission #734451

#TimeUsernameProblemLanguageResultExecution timeMemory
734451rahidilbayramliTracks in the Snow (BOI13_tracks)C++17
100 / 100
868 ms130536 KiB
#include<bits/stdc++.h> #define ll long long #define vl vector<ll> #define sl set<ll> #define all(v) v.begin(), v.end() #define pb push_back #define s second #define f first #define pll pair<ll, ll> #define pii pair<int, int> using namespace std; int n, m, i, j, depth[4001][4001]; int neighborx[4] = {-1, 1, 0, 0}; int neighbory[4] = {0, 0, 1, -1}; string a[4001]; bool isvalid(int c, int d) { if(c < 0 || d < 0 || c >= n || d >= m || a[c][d] == '.') return false; return true; } int main() { cin >> n >> m; for(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.f, y = s.s; ans = max(ans, depth[x][y]); for(i = 0; i < 4; i++) { int nx = x + neighborx[i], ny = y + neighbory[i]; if(isvalid(nx, ny) && 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 << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...