제출 #203433

#제출 시각아이디문제언어결과실행 시간메모리
203433mdn2002Tracks in the Snow (BOI13_tracks)C++14
19.79 / 100
1415 ms132024 KiB
#include<bits/stdc++.h> using namespace std; char a[4050][4050]; int n,m,dis[4050][4050],xx[]={1,-1,0,0},yy[]={0,0,1,-1},ans; int main() { cin>>n>>m; for(int i=0; i<n; i++)cin>>a[i]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++)dis[i][j]=1e9; } deque<pair<int,int> >dq; dq.push_front({0,0}); dis[0][0]=1; while(dq.size()) { pair<int,int>pr=dq.front(); dq.pop_front(); int ox=pr.first,oy=pr.second; for(int i=0; i<4; i++) { int x=ox+xx[i],y=oy+yy[i]; if(0<=x&&x<n&&0<=y&&y<m&&a[x][y]!='.') { int pls=0; if(a[ox][oy]!=a[x][y])pls++; if(dis[x][y]>dis[ox][oy]+pls) { dis[x][y]=dis[ox][oy]+pls; if(pls)dq.push_back({x,y}); else dq.push_front({x,y}); } } } } for(int i=0;i<n;i++) { for(int j=0;j<m;j++)ans=max(ans,dis[i][j]); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...