Submission #639573

#TimeUsernameProblemLanguageResultExecution timeMemory
639573AdiCoder03Tracks in the Snow (BOI13_tracks)C++17
100 / 100
1022 ms175784 KiB
#include<bits/stdc++.h> typedef long long ll; #define vi vector<int> #define pb push_back #define self_min(a, b) a = min(a, b) #define self_max(a, b) a = max(a, b) #define V vector #define yes cout<<"YES\n"; #define no cout<<"NO\n"; #define fs(lcv, hi) for(lcv = 0; lcv < hi; lcv ++) #define fb(lcv, hi) for(lcv = hi; lcv >= 0; lcv --) #define loop(lcv, lower, upper) for(lcv = lower; lcv < upper; lcv++) #define crd(pii) [pii.first][pii.second] using namespace std; int h, w; bool within(pair<int, int> p) { int x, y; tie(x, y) = p; if(x >= 0 && x < h && y >= 0 && y < w) { return 1; } return 0; } pair<int, int> operator +(pair<int, int> p1, pair<int, int> p2) { return {p1.first + p2.first, p1.second + p2.second}; } void solve() { int i, j; cin >> h; cin >> w; V<string> grid(h); fs(i, h) cin >> grid[i]; vector<pair<int, int>> dx = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; deque <pair<int, int>> bfsq = {{0, 0}}; V<vi> distances(h, vi(w, 0)); V<V<bool>> vis(h, V<bool>(w, 0)); distances[0][0] = 1; int ans = 0; while(!bfsq.empty()) { pair<int, int> pt = bfsq.front(); // cout << pt.first << " " << pt.second << " " << distances crd(pt) << "\n"; vis crd(pt) = 1; self_max(ans, distances crd(pt)); bfsq.pop_front(); self_max(ans, distances crd(pt)); for(auto xdx : dx) { pair<int, int> curr = pt + xdx; // cout << curr.first << " " << curr.second << "Hola\n"; if(within(curr) && !vis crd(curr) && grid crd(curr) != '.') { if(grid crd(curr) != grid crd(pt)) { distances crd(curr) = distances crd(pt) + 1; bfsq.push_back(curr); } else { distances crd(curr) = distances crd(pt); bfsq.push_front(curr); } } } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }

Compilation message (stderr)

tracks.cpp: In function 'void solve()':
tracks.cpp:38:12: warning: unused variable 'j' [-Wunused-variable]
   38 |     int i, j;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...