Submission #101544

#TimeUsernameProblemLanguageResultExecution timeMemory
101544rainyTracks in the Snow (BOI13_tracks)C++14
0 / 100
4 ms532 KiB
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<utility> #include<queue> #define INF 32000 using namespace std; typedef vector<short> vi; typedef pair<short,short>ii; short H,W; char X; short dx[]={0,1,0,-1},dy[]={1,0,-1,0}; void prvt(vector<vi> vv){ printf("---\n"); for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ if(vv[i][j]==-1)printf("-"); else printf("%hd",vv[i][j]); } printf("\n"); } printf("---\n"); } short tis(vector<vi> x, short ani){ queue<ii>q;q.push(ii(0,0)); x[0][0]=-1; bool vis[H+5][W+5]={false}; vis[0][0]=true; while(!q.empty()){ int x1=q.front().first,y1=q.front().second; q.pop(); for(int k=0;k<4;k++){ int nx=x1+dx[k],ny=y1+dy[k]; if(0<=nx&&nx<H&&0<=ny&&ny<W){ if(!vis[nx][ny]){ if(x[nx][ny]==-1||x[nx][ny]==ani){ vis[nx][ny]=true; x[nx][ny]=-1; q.push(ii(nx,ny)); } } } } } //prvt(x); if(!vis[H-1][W-1])return INF; bool isDone=true;bool has1=false,has2=false; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ if(x[i][j]==1){ has1=true;isDone=false; } if(x[i][j]==2){ has2=true;isDone=false; } } } if(isDone)return 0; short ans=INF; if(has1)ans=tis(x,1); if(has2)ans=min(tis(x,2),ans); return 1+ans; } int main(){ scanf("%d%d",&H,&W); vector<vi> gr(H); for(int i=0;i<H;i++){ vi xyz(W); for(int j=0;j<W;j++){ xyz[j]=-1; } gr[i]=xyz; } for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ scanf(" %c",&X); if(X=='.')gr[i][j]=0; if(X=='F')gr[i][j]=1; if(X=='R')gr[i][j]=2; } } /* for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ printf("%d",gr[i][j]); } printf("\n"); } */ printf("%hd\n",1+tis(gr,gr[0][0])); return 0; }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:69:23: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'short int*' [-Wformat=]
     scanf("%d%d",&H,&W);
                  ~~   ^
tracks.cpp:69:23: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'short int*' [-Wformat=]
tracks.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&H,&W);
     ~~~~~^~~~~~~~~~~~~~
tracks.cpp:80:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c",&X);
             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...