# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199452 | TadijaSebez | Tracks in the Snow (BOI13_tracks) | C++11 | 726 ms | 112692 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=4050;
char s[N][N];
int dist[N][N],n,m;
int mv[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
bool ok(int x,int y){return x>=1 && x<=n && y>=1 && y<=m && s[x][y]!='.';}
int main(){
scanf("%i %i",&n,&m);
for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dist[i][j]=1e9;
deque<int> q;
q.push_back(1*N+1);
dist[1][1]=1;
int ans=0;
while(q.size()){
int x=q.front()/N;
int y=q.front()%N;
q.pop_front();
ans=max(ans,dist[x][y]);
for(int k=0;k<4;k++){
int i=x+mv[k][0];
int j=y+mv[k][1];
if(ok(i,j)){
int w=s[x][y]!=s[i][j];
if(dist[i][j]>dist[x][y]+w){
dist[i][j]=dist[x][y]+w;
if(w==0)q.push_front(i*N+j);
else q.push_back(i*N+j);
}
}
}
}
printf("%i\n",ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |