Submission #1318706

#TimeUsernameProblemLanguageResultExecution timeMemory
1318706mibngorTracks in the Snow (BOI13_tracks)C++20
70.94 / 100
851 ms355740 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define pp pop_back #define emp emplace_back #define ins insert #define fi first #define se second #define sz(x) x.size() #define fop if(fopen("hello.inp","r")){freopen("hello.inp","r",stdin);freopen("hello.out","w",stdout);} #define ls ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); ll Rd(ll l,ll r) { return uniform_int_distribution<int>(l,r)(rd); } const int N = 4e3 + 7; int h,w,x[4] = {0,1,0,-1},y[4] = {1,0,-1,0},rs = -1,dist[N][N]; bool vst[N][N]; char a[N][N]; void bfs(ll nx,ll ny) { deque<pair<int,int>> dq; dq.push_back({nx,ny}); dist[nx][ny] = 1; while(!dq.empty()) { auto u = dq.front(); dq.pop_front(); if(vst[u.fi][u.se]) continue; vst[u.fi][u.se] = 1; rs = max(rs,dist[u.fi][u.se]); for(int i = 0; i < 4; i++) { pair<int,int> v; v.fi = u.fi + x[i]; v.se = u.se + y[i]; if(v.fi < 1 || v.fi > h) continue; if(v.se < 1 || v.se > h) continue; if(a[v.fi][v.se] == '.') continue; if(a[v.fi][v.se] != a[u.fi][u.se]) { dq.push_back(v); dist[v.fi][v.se] = dist[u.fi][u.se] + 1; } else { dq.push_front(v); dist[v.fi][v.se] = dist[u.fi][u.se]; } } } } main() { fop; ls; cin >> h >> w; for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++) cin >> a[i][j]; bfs(1,1); cout << rs; }

Compilation message (stderr)

tracks.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main()
      | ^~~~
tracks.cpp: In function 'int main()':
tracks.cpp:10:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | #define fop if(fopen("hello.inp","r")){freopen("hello.inp","r",stdin);freopen("hello.out","w",stdout);}
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:61:5: note: in expansion of macro 'fop'
   61 |     fop;
      |     ^~~
tracks.cpp:10:78: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | #define fop if(fopen("hello.inp","r")){freopen("hello.inp","r",stdin);freopen("hello.out","w",stdout);}
      |                                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:61:5: note: in expansion of macro 'fop'
   61 |     fop;
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...