Submission #533630

#TimeUsernameProblemLanguageResultExecution timeMemory
533630groshiTracks in the Snow (BOI13_tracks)C++17
62.81 / 100
2097 ms94460 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 ile[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]; queue<pair<int,pair<int,int> > > kolejka; kolejka.push({-1,{1,1}}); odw[1][1]=1; int wynik=0; while(!kolejka.empty()) { pair<int,pair<int,int> > para=kolejka.front(); kolejka.pop(); ile[para.second.first][para.second.second]=-para.first; for(int i=0;i<4;i++) { int nowy_x=dx[i]+para.second.first; int nowy_y=dy[i]+para.second.second; if(nowy_x<1 || nowy_x>n || nowy_y<1 || nowy_y>m) continue; if(t[nowy_x][nowy_y]=='.') continue; if(odw[nowy_x][nowy_y]==0) { odw[nowy_x][nowy_y]=1; if(t[nowy_x][nowy_y]!=t[para.second.first][para.second.second]) { kolejka.push({para.first-1,{nowy_x,nowy_y}}); ile[nowy_x][nowy_y]=-para.first+1; } else { kolejka.push({para.first,{nowy_x,nowy_y}}); ile[nowy_x][nowy_y]=-para.first; } } else{ if(t[nowy_x][nowy_y]!=t[para.second.first][para.second.second] && ile[nowy_x][nowy_y]>-para.first+1) { kolejka.push({para.first-1,{nowy_x,nowy_y}}); ile[nowy_x][nowy_y]=-para.first+1; } else if(t[nowy_x][nowy_y]==t[para.second.first][para.second.second] && ile[nowy_x][nowy_y]>-para.first) { ile[nowy_x][nowy_y]=-para.first; kolejka.push({para.first,{nowy_x,nowy_y}}); } } if(odw[nowy_x][nowy_y]==1 || t[nowy_x][nowy_y]=='.') 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}}); odw[nowy_x][nowy_y]=1; } } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) wynik=max(wynik,ile[i][j]); cout<<wynik; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...