Submission #890069

#TimeUsernameProblemLanguageResultExecution timeMemory
890069math_piTracks in the Snow (BOI13_tracks)C++14
100 / 100
436 ms137824 KiB
#include<bits/stdc++.h> using namespace std; int n, m; string s[5000]; int dp[5000][5000]; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, 1, -1}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i=0; i<n; i++) { cin >> s[i]; } deque<pair<int, int>> q; q.push_back({0, 0}); dp[0][0] = 1; int ans = 0; while(!q.empty()) { auto me = q.front(); q.pop_front(); ans = max(ans, dp[me.first][me.second]); for(int to=0; to<4; to++) { int i = me.first +dx[to], j = me.second + dy[to]; if(i>=0&&i<n&&j>=0&&j<m&&s[i][j]!='.') { if(dp[i][j]==0) { if(s[i][j]!=s[me.first][me.second]) { dp[i][j] = dp[me.first][me.second] + 1; q.push_back({i, j}); } else { dp[i][j] = dp[me.first][me.second]; q.push_front({i, j}); } } } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...