# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
346467 | ahmet | Tracks in the Snow (BOI13_tracks) | C++14 | 1242 ms | 227452 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ref(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define rep(a,b) for(int (a)=0;(a)<(b);++(a))
#define pb push_back
#define mp make_pair
const int mx=5000;
int n,m;
char a[mx][mx];
int depth[mx][mx];
int vis[mx][mx];
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
int check(int x,int y){
if(x==0 or y==0 or x==n+1 or y==m+1 or a[x][y]=='.' or vis[x][y])return 1;
else return 0;
}
int ans=1;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
cin >> a[i][j];
}
}
rep(i,mx)rep(j,mx)depth[i][j]=2e9;
depth[1][1]=1;
deque <pair <int,int> > q;
q.push_front(mp(1,1));
while(!q.empty()){
int x=q.front().first;
int y=q.front().second;
q.pop_front();
if(vis[x][y])continue;
else vis[x][y]=1;
//cout << x << " " << y << " " << depth[x][y] << endl;
//if(x==1 and y==5)cout<<"BURda";
ans=max(ans,depth[x][y]);
for(int i=0;i<4;++i){
int gox=x+dx[i];int goy=y+dy[i];
// if(x==1 and y==5)cout<<gox << " " << goy << endl;
if(check(gox,goy))continue;
if(a[gox][goy]==a[x][y] and depth[gox][goy]>depth[x][y]){
depth[gox][goy]=depth[x][y];
q.push_front(mp(gox,goy));
// if(x==1 and y==5)cout<<"BURDa 1 " << i << endl;
}
else if(a[gox][goy]!=a[x][y] and depth[gox][goy]>depth[x][y]+1){
depth[gox][goy]=depth[x][y]+1;
q.push_back(mp(gox,goy));
//if(x==1 and y==5)cout<<"BURDa 2 " << i << endl;
}
}
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |