제출 #768684

#제출 시각아이디문제언어결과실행 시간메모리
768684green_gold_dogMaze (JOI23_ho_t3)C++17
67 / 100
2061 ms43352 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1'000'000'000; template<typename T> bool assign_min(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<typename T> bool assign_max(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct segment_tree { vector<bool> tree; ll size; segment_tree(ll n) { size = n; tree.resize(size * 4, false); } vector<ll> set(ll l, ll r) { vector<ll> ans; set(1, 0, size, l, r, ans); return ans; } void set(ll v, ll l, ll r, ll ql, ll qr, vector<ll>& ans) { if (tree[v]) { return; } if (r <= ql || qr <= l) { return; } if (r - l == 1) { ans.push_back(l); tree[v] = true; return; } ll mid = (l + r) / 2; set(v * 2, l, mid, ql, qr, ans); set(v * 2 + 1, mid, r, ql, qr, ans); tree[v] = tree[v * 2] && tree[v * 2 + 1]; } }; void solve() { ll n, r, c; cin >> r >> c >> n; ll sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--; vector<vector<bool>> arr(r, vector<bool>(c, false)); vector<vector<bool>> used(r, vector<bool>(c, false)); vector<segment_tree> dist(r, segment_tree(c)); for (ll i = 0; i < r; i++) { string s; cin >> s; for (ll j = 0; j < c; j++) { if (s[j] == '.') { arr[i][j] = true; } } } queue<pair<ll, ll>> now; now.emplace(sx, sy); used[sx][sy] = true; ll na = 0; while (true) { vector<pair<ll, ll>> nu; while (!now.empty()) { auto[x, y] = now.front(); nu.emplace_back(x, y); if (x == gx && y == gy) { cout << na << '\n'; return; } now.pop(); if (x > 0 && arr[x - 1][y]) { if (!used[x - 1][y]) { used[x - 1][y] = true; now.emplace(x - 1, y); } } if (x + 1 < r && arr[x + 1][y]) { if (!used[x + 1][y]) { used[x + 1][y] = true; now.emplace(x + 1, y); } } if (y > 0 && arr[x][y - 1]) { if (!used[x][y - 1]) { used[x][y - 1] = true; now.emplace(x, y - 1); } } if (y + 1 < c && arr[x][y + 1]) { if (!used[x][y + 1]) { used[x][y + 1] = true; now.emplace(x, y + 1); } } } na++; for (auto[x, y] : nu) { for (ll i = -n; i <= n; i++) { if (x + i >= 0 && x + i < r) { if (abs(i) == n) { for (auto j : dist[x + i].set(max(y - n + 1, 0ll), min(y + n, c))) { if (!used[x + i][j]) { used[x + i][j] = true; now.emplace(x + i, j); } } } else { for (auto j : dist[x + i].set(max(y - n, 0ll), min(y + n + 1, c))) { if (!used[x + i][j]) { used[x + i][j] = true; now.emplace(x + i, j); } } } } } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...