Submission #415977

#TimeUsernameProblemLanguageResultExecution timeMemory
415977nkatoTracks in the Snow (BOI13_tracks)C++17
100 / 100
931 ms128300 KiB
#include <bits/stdc++.h> #define ll long long #define vi vector<int> #define pi pair<int, int> #define se second #define fi first #define vt vector #define pb push_back #define nl endl #define dbg(...) " [" << #__VA_ARGS__": " << (__VA_ARGS__) << "] " #define all(v) v.begin(), v.end() #define FORN(a, b, i) for(int i = (a); i < (b); i++) #define FORE(a, b, i) for(int i = (a); i <= (b); i++) #define FOR(a, i) for(int i = 0; i < (a); i++) #define trav(x, a) for (auto& a : x) using namespace std; void setIO(string name) { ios_base::sync_with_stdio(0); cin.tie(0); if (name.empty()) return; freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int nax = 4000; string b[nax]; int dep[nax][nax]; int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, 1, -1}; int n, m; bool inside(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m && b[x][y] != '.'); } int main() { memset(dep, -1, sizeof(dep)); cin >> n >> m; FOR(n, i) cin >> b[i]; deque<pair<int, int>> d; dep[0][0] = 1; d.push_back({0, 0}); int ans = 0; while(!d.empty()) { pi u = d.front(); d.pop_front(); ans = max(ans, dep[u.fi][u.se]); FOR(4, i) { pi v = {u.fi+dx[i], u.se+dy[i]}; if (inside(v.fi, v.se) && dep[v.fi][v.se] == -1) { if (b[v.fi][v.se] == b[u.fi][u.se]) { dep[v.fi][v.se] = dep[u.fi][u.se]; d.push_front(v); } else { dep[v.fi][v.se] = dep[u.fi][u.se]+1; d.push_back(v); } } } } cout << ans << endl; return 0; }

Compilation message (stderr)

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