Submission #533628

#TimeUsernameProblemLanguageResultExecution timeMemory
533628groshiTracks in the Snow (BOI13_tracks)C++17
6.67 / 100
2094 ms229760 KiB
#include<iostream> #include<queue> #include<utility> using namespace std; int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; char t[4010][4010]; bool odw[4010][4010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>t[i][j]; priority_queue<pair<int,pair<int,int> > > kolejka; kolejka.push({-1,{1,1}}); int wynik=0; while(!kolejka.empty()) { pair<int,pair<int,int> > para=kolejka.top(); kolejka.pop(); if(odw[para.second.first][para.second.second]==1) continue; wynik=max(wynik,-para.first); odw[para.second.first][para.second.second]=1; for(int i=0;i<4;i++) { int nowy_x=dx[i]+para.second.first; int nowy_y=dy[i]+para.second.second; if(odw[nowy_x][nowy_y]==1) continue; if(nowy_x<1 || nowy_x>n || nowy_y<1 || nowy_y>m) continue; if(t[nowy_x][nowy_y]!=t[para.second.first][para.second.second]) kolejka.push({para.first-1,{nowy_x,nowy_y}}); else kolejka.push({para.first,{nowy_x,nowy_y}}); } } cout<<wynik; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...