Submission #724391

#TimeUsernameProblemLanguageResultExecution timeMemory
724391chanhchuong123Tracks in the Snow (BOI13_tracks)C++14
100 / 100
773 ms138752 KiB
#include <bits/stdc++.h> using namespace std; #define task "" #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int dx[] = {-1, 0, 0, +1}; const int dy[] = {0, -1, +1, 0}; const int MAX = 4000; int n, m; int ans = 0; int d[MAX][MAX]; char a[MAX][MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; memset(d, 0x3f, sizeof d); deque<pair<int, int>> dq; dq.push_front({0, 0}); d[0][0] = 1; while (dq.size()) { int u = dq.front().fi; int v = dq.front().se; maximize(ans, d[u][v]); dq.pop_front(); for (int i = 0; i < 4; ++i) { int x = u + dx[i], y = v + dy[i]; if (x < 0 || x >= n) continue; if (y < 0 || y >= m) continue; if (a[x][y] != '.') { int w = a[u][v] != a[x][y]; if (minimize(d[x][y], d[u][v] + w)) { if (w) dq.push_back({x, y}); else dq.push_front({x, y}); } } } } cout << ans; return 0; }

Compilation message (stderr)

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