Submission #464488

#TimeUsernameProblemLanguageResultExecution timeMemory
464488AratabTracks in the Snow (BOI13_tracks)C++17
100 / 100
633 ms130928 KiB
/** * Author : Samuel Batara (Aratab) **/ #include <bits/stdc++.h> using namespace std; int N,M; string s[4001]; int dep[4001][4001]; vector<int> dx = {1,0,-1,0}; vector<int> dy = {0,1,0,-1}; bool inside(int x, int y) { return (x>-1 && x<N && y>-1 && y<M && s[x][y]!='.'); } void dahiken() { cin >> N >> M; for(int i=0; i<N; i++) cin >> s[i]; dep[0][0] = 1; deque<pair<int,int>> q; q.push_back({0,0}); int ans = 1; while(!q.empty()) { int a,b; tie(a,b) = q.front(); q.pop_front(); ans = max(ans, dep[a][b]); for(int i=0; i<4; i++) { int x = a + dx[i], y = b + dy[i]; if(inside(x,y) && dep[x][y]==0) { if(s[a][b] == s[x][y]) { dep[x][y] = dep[a][b]; q.push_front({x,y}); } else { dep[x][y] = dep[a][b] + 1; q.push_back({x,y}); } } } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int ntc=1; //cin >> ntc; while(ntc--) { dahiken(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...