Submission #1299024

#TimeUsernameProblemLanguageResultExecution timeMemory
1299024random_nameTracks in the Snow (BOI13_tracks)C++20
100 / 100
642 ms110676 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int h,w;cin>>h>>w; vector<vector<char>> snow(h, vector<char>(w)); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin>>snow[i][j]; } } vector<vector<int>> swaps(h, vector<int>(w, -1)); deque<pair<int, int>> dq; dq.push_front({0, 0}); swaps[0][0] = 1; pair<int, int> GOES[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; while(!dq.empty()){ pair<int, int> c=dq.front(); dq.pop_front(); for(pair<int, int> go:GOES){ int x=c.first+go.first, y=c.second+go.second; if(x < 0 || x >= h || y < 0 || y >= w) continue; if(snow[x][y] == '.' || swaps[x][y] != -1) continue; if(snow[x][y] == snow[c.first][c.second]){ dq.push_front({x, y}); swaps[x][y] = swaps[c.first][c.second]; } else{ dq.push_back({x, y}); swaps[x][y] = swaps[c.first][c.second]+1; } } } int mx=0; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ // cout << swaps[i][j] << ' '; mx = max(mx, swaps[i][j]); } // cout << '\n'; } cout << mx << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...