Submission #1274243

#TimeUsernameProblemLanguageResultExecution timeMemory
1274243tkhoi13Tracks in the Snow (BOI13_tracks)C++20
100 / 100
600 ms122144 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define db double #define pii pair<int, int> #define fi first #define se second #define pb push_back #define all(x) begin(x), end(x) #define allr(x) rbegin(x), rend(x) #define szx(x) ((int)(x).size()) #define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; ++i) #define ROF(i, a, b) for (int i = a, _b = (b); i >= _b; --i) #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define endl '\n' #define inf 1000000007 #define mod 1000000007 using namespace std; using namespace __gnu_pbds; void setIO(string filename = "") { ios::sync_with_stdio(0); cin.tie(0); if (!filename.empty()) { if (ifstream(filename + ".in")) { freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } } } int dx[]{0, 1, -1, 0}; int dy[]{1, 0, 0, -1}; int h, w; vector<vector<char>> table; bool valid(int x, int y) { return (x >= 0 && y >= 0 && x < h && y < w && table[x][y] != '.'); } void solve() { cin >> h >> w; table.assign(h, vector<char>(w)); REP(i, h) REP(j, w) cin >> table[i][j]; int ans = 0; vector<vector<int>> dis(h, vector<int>(w, 1e9)); deque<pii> dq; dq.pb({0, 0}); dis[0][0] = 1; while (!dq.empty()) { pii v = dq.front(); dq.pop_front(); ans = max(ans, dis[v.fi][v.se]); #define d(x) (x).fi][(x).se REP(i, 4) { if (valid(v.fi + dx[i], v.se + dy[i]) && dis[v.fi + dx[i]][v.se + dy[i]] == 1e9) { if (table[d(v)] == table[v.fi + dx[i]][v.se + dy[i]]) { dis[v.fi + dx[i]][v.se + dy[i]] = dis[d(v)]; dq.push_front({v.fi + dx[i], v.se + dy[i]}); } else { dis[v.fi + dx[i]][v.se + dy[i]] = dis[d(v)] + 1; dq.push_back({v.fi + dx[i], v.se + dy[i]}); } } } } cout << ans; } void preprocess() {} int main() { setIO("main"); int t = 1; // cin >> t; preprocess(); while (t--) { solve(); } }

Compilation message (stderr)

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