Submission #492134

#TimeUsernameProblemLanguageResultExecution timeMemory
492134ToroTNTracks in the Snow (BOI13_tracks)C++14
31.25 / 100
487 ms78648 KiB
#include<bits/stdc++.h> using namespace std; int n,m,dx[]={1,-1,0,0},dy[]={0,0,1,-1},d[4005][4005],u,v,sx,sy,x,y; char s[4005][4005]; queue<pair<int,int> > q; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%s",s[i]+1); } sx=1; sy=1; for(int i=1;;i++) { //printf("%d\n",i); q.push({sx,sy}); d[sx][sy]=1; sx=-1; sy=-1; while(!q.empty()) { u=q.front().first; v=q.front().second; ///printf("%d %d %d\n",u,v,d[u][v]); q.pop(); for(int j=0;j<4;j++) { x=u+dx[j]; y=v+dy[j]; if(x>=1&&x<=n&&y>=1&&y<=m) { if(s[x][y]!='.') { if(s[x][y]!=s[u][v]) { if(d[x][y]==0) { sx=x; sy=y; } }else { //printf("%d %d %d %d\n",u,v,x,y); if(d[x][y]==0) { //printf("%d %d %d\n",x,y,d[x][y]); d[x][y]=1; q.push({x,y}); } } } } } } if(sx==-1&&sy==-1) { printf("%d\n",i); break; } } }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
tracks.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%s",s[i]+1);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...