Submission #854113

#TimeUsernameProblemLanguageResultExecution timeMemory
854113nhatvpmTracks in the Snow (BOI13_tracks)C++17
100 / 100
547 ms124000 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void setIO(string name) { freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } void solve(){ int n,m,dx[]={0,0,1,-1},dy[]={1,-1,0,0}; cin>>n>>m; string grid[n]; for (int i=0;i<n;i++) cin>>grid[i]; deque<pair<int,int>> q; vector<vector<int>> dis(n,vector<int>(m,0)); dis[0][0]=1; int res=0; q.push_front({0,0}); while (!q.empty()){ int x=q.front().first,y=q.front().second; res=max(res,dis[x][y]); q.pop_front(); for (int i=0;i<4;i++){ int r=x+dx[i],c=y+dy[i]; if (r>=0&&r<n&&c>=0&&c<m&&grid[r][c]!='.'&&dis[r][c]==0){ int w=grid[r][c]!=grid[x][y]?1:0; dis[r][c]=dis[x][y]+w; if (w==1) q.push_back({r,c}); else q.push_front({r,c}); } } } cout<<res; } int main(){ //setIO(""); ios_base::sync_with_stdio(0); cin.tie(0); int tc=1; //cin>>tc; while (tc--){ solve(); } }

Compilation message (stderr)

tracks.cpp: In function 'void setIO(std::string)':
tracks.cpp:7:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:8:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...