Submission #492124

#TimeUsernameProblemLanguageResultExecution timeMemory
492124ToroTNTracks in the Snow (BOI13_tracks)C++14
65 / 100
2097 ms59752 KiB
#include<bits/stdc++.h> using namespace std; short n,m,d[4005][4005],u,v,dx[]={1,-1,0,0},dy[]={0,0,1,-1},x,y,mx=-1; char s[4005][4005]; priority_queue<tuple<short,short,short> > pq; int main() { scanf("%hd%hd",&n,&m); for(int i=1;i<=n;i++) { scanf("%s",s[i]+1); for(int j=1;j<=m;j++) { d[i][j]=20000; } } d[1][1]=1; pq.push({0,1,1}); while(!pq.empty()) { u=get<1>(pq.top()); v=get<2>(pq.top()); mx=max(mx,d[u][v]); pq.pop(); for(int i=0;i<4;i++) { x=u+dx[i]; y=v+dy[i]; if(x>=1&&x<=n&&y>=1&&y<=m) { if(s[x][y]!='.') { if(s[x][y]!=s[u][v]) { if(d[u][v]+1<d[x][y]) { d[x][y]=d[u][v]+1; pq.push({-d[x][y],x,y}); } }else { if(d[u][v]<d[x][y]) { d[x][y]=d[u][v]; pq.push({-d[x][y],x,y}); } } } } } } printf("%hd\n",mx); }

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("%hd%hd",&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...