제출 #736247

#제출 시각아이디문제언어결과실행 시간메모리
736247rahidilbayramliTracks in the Snow (BOI13_tracks)C++17
100 / 100
838 ms135524 KiB
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define vl vector<ll> #define sl set<ll> #define conn continue #define tests while(t--) #define pii pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define f first #define s second using namespace std; const int sz = 4005; int neighborx[4] = {1, -1, 0, 0}; int neighbory[4] = {0, 0, 1, -1}; int depth[sz][sz], n, m, i, j; string a[sz]; 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<pii>q; q.pb({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] = depth[x][y] + 1; q.pb({nx, ny}); } } } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...