Submission #575987

#TimeUsernameProblemLanguageResultExecution timeMemory
575987OnionEggTracks in the Snow (BOI13_tracks)C++17
100 / 100
594 ms231780 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") #include<bits/stdc++.h> #define ll long long #define fas ios::sync_with_stdio(0); cout.tie(0); cin.tie(0) #define el "\n" #define fi first #define se second #define th third #define taskName "codefuck" using namespace std; const ll mod = 1e9+7; ll dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1}; ll n, m, depth[4005][4005], res; string snow[4000]; bool inside(ll x, ll y) { return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.'); } void solve() { cin >> n >> m; for(int i = 0; i < n; i++) cin >> snow[i]; deque<pair<ll, ll>>q; q.push_back({0, 0}); depth[0][0] = 1; res = 1; while(q.size()) { pair<ll, ll> c = q.front(); q.pop_front(); res = max(res, depth[c.fi][c.se]); for(int i = 0; i < 4; i++) { ll x = c.fi + dx[i], y = c.se + dy[i]; if(inside(x, y) && depth[x][y] == 0) { if(snow[x][y] == snow[c.fi][c.se]) { depth[x][y] = depth[c.fi][c.se]; q.push_front({x, y}); } else { depth[x][y] = depth[c.fi][c.se] + 1; q.push_back({x, y}); } } } } cout << res; } int main() { fas; if (fopen(taskName".inp", "r")) { freopen(taskName".inp", "r", stdin); freopen(taskName".out", "w", stdout); } ll testcase = 1; //cin >> testcase; while(testcase--) { solve(); } }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(taskName".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(taskName".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...