Submission #658881

#TimeUsernameProblemLanguageResultExecution timeMemory
658881ansgarTracks in the Snow (BOI13_tracks)C++17
100 / 100
571 ms235728 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define vi vector<int> #define vvi vector<vi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define vb vector<bool> #define vc vector<char> #define vvc vector<vc> #define vvb vector<vb> #define si set<int> #define mii map<int,int> const int mod=1e9+7; const int N=2e5+1; const int LN=LLONG_MAX/10; int dx[4]{1,-1,0,0},dy[4]{0,0,1,-1}; int n,m,depth[4000][4000],ans=1; string snow[4000]; bool inside(int x,int y){ return (x>-1 and x<n and y>-1 and y<m and snow[x][y]!='.'); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m; for(int i=0;i<n;i++)cin>>snow[i]; deque<pii> Q; Q.push_back({0,0}); depth[0][0]=1; while(Q.size()){ pii c=Q.front(); Q.pop_front(); ans=max(ans,depth[c.first][c.second]); for(int i=0;i<4;i++){ int x=c.first+dx[i],y=c.second+dy[i]; if(inside(x,y) and depth[x][y]==0){ if(snow[x][y]==snow[c.first][c.second]){ depth[x][y]=depth[c.first][c.second]; Q.push_front({x,y}); } else{ depth[x][y]=depth[c.first][c.second]+1; Q.push_back({x,y}); } } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...