# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101838 | rainy | Tracks in the Snow (BOI13_tracks) | C++14 | 2102 ms | 299684 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int H,W;
char gr[4005][4005],ca,idk='a';
int vis[4005][4005];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
void dfs(int x,int y){
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(0<=nx&&nx<H&&0<=ny&&ny<W){
if(!vis[nx][ny]&&(gr[nx][ny]==ca||gr[nx][ny]==idk)){
vis[nx][ny]=1;
gr[nx][ny]=idk;
dfs(nx,ny);
}
}
}
}
int main(){
scanf("%d%d",&H,&W);
for(int i=0;i<H;i++){
for(int j=0;j<W;j++)scanf(" %c",&gr[i][j]);
}
ca=gr[0][0];
int ans=0;
while(true){
ans++;
memset(vis,0,sizeof(vis));
dfs(0,0);
if(ca=='F')ca='R';
else ca='F';
bool isD=true;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(gr[i][j]=='F'||gr[i][j]=='R')isD=false;
}
}
if(isD)break;
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |