# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101685 | jamielim | Tracks in the Snow (BOI13_tracks) | C++14 | 999 ms | 110692 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int h,w;
scanf("%d%d",&h,&w);
char grid[h+5][w+5];
for(int i=0;i<h;i++)scanf("%s",grid[i]);
deque<pair<int,int> > q;
q.push_back(make_pair(0,0));
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int dist[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++)dist[i][j]=1000000010;
}
dist[0][0]=1;
while(!q.empty()){
pair<int,int> cur=q.front();q.pop_front();
for(int i=0;i<4;i++){
int nx=cur.first+dx[i],ny=cur.second+dy[i];
if(0<=nx&&nx<h&&0<=ny&&ny<w&&grid[nx][ny]!='.'){
if(grid[nx][ny]==grid[cur.first][cur.second]){
if(dist[nx][ny]>dist[cur.first][cur.second]){
dist[nx][ny]=dist[cur.first][cur.second];
q.push_front(make_pair(nx,ny));
}
}else{
if(dist[nx][ny]>dist[cur.first][cur.second]+1){
dist[nx][ny]=dist[cur.first][cur.second]+1;
q.push_back(make_pair(nx,ny));
}
}
}
}
}
int ans=1;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(dist[i][j]<1000000010)ans=max(ans,dist[i][j]);
}
}
printf("%d",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |