Submission #1001250

#TimeUsernameProblemLanguageResultExecution timeMemory
1001250vjudge3Tracks in the Snow (BOI13_tracks)C++17
100 / 100
1662 ms169620 KiB
#include <bits/stdc++.h> using namespace std; bitset<4005> vis[4005], occ[4005], fox[4005]; vector<pair<int, int>> cur; int h, w, dep = 1; const int dr[4] = {0, 1, 0, -1}, dc[4] = {1, 0, -1, 0}; void bfs (int rt, int ct, bool f) { queue<pair<int, int>> q; q.push({rt, ct}); while (!q.empty()) { auto [r, c] = q.front(); q.pop(); for (int k = 0; k < 4; k++) { int rv = r + dr[k], cv = c + dc[k]; if (rv >= 1 && rv <= h && cv >= 1 && cv <= w && !vis[rv][cv] && occ[rv][cv] && fox[rv][cv] == f) { q.push({rv, cv}); cur.push_back({rv, cv}); vis[rv][cv] = true; } } } } int main () { cin >> h >> w; for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) { char ch; cin >> ch; if (ch != '.') occ[i][j] = true; if (ch == 'F') fox[i][j] = true; } bfs(1, 1, fox[1][1]); while (true) { vector<pair<int, int>> last; last.swap(cur); for (auto& [r, c] : last) bfs(r, c, (dep & 1) ^ fox[1][1]); last.clear(); if (cur.empty()) { cout << dep << '\n'; return 0; } dep++; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...