Submission #937666

#TimeUsernameProblemLanguageResultExecution timeMemory
937666zwezdinvMaze (JOI23_ho_t3)C++17
8 / 100
151 ms79400 KiB
#include <bits/stdc++.h> struct node { int x, y, free, dist; node() = default; node(int x, int y, int free, int dist) : x(x), y(y), free(free), dist(dist) {} }; std::vector<std::pair<int, int>> dir1 = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} }; std::vector<std::pair<int, int>> dir2 = { {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1} }; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int r, c, n; std::cin >> r >> c >> n; int sx, sy, fx, fy; std::cin >> sx >> sy >> fx >> fy; --sx, --sy, --fx, --fy; std::vector a(r, std::vector(c, '#')); for (auto& i : a) { for (auto& j : i) { std::cin >> j; } } std::deque<node> que; std::vector used(r, std::vector(c, false)); que.emplace_back(sx, sy, 0, 0); while (que.size()) { node u = que.front(); que.pop_front(); if (u.x == fx && u.y == fy) { std::cout << u.dist << '\n'; break; } if (used[u.x][u.y]) continue; used[u.x][u.y] = true; for (auto [dx, dy] : dir1) { int i = u.x + dx, j = u.y + dy; if (i < 0 || i >= r || j < 0 || j >= c) continue; if (a[i][j] == '.') { que.emplace_front(i, j, std::max(u.free - 1, 0), u.dist); } } for (auto [dx, dy] : dir2) { int i = u.x + dx, j = u.y + dy; if (i < 0 || i >= r || j < 0 || j >= c) continue; if (u.free >= abs(dx) + abs(dy)) { que.emplace_front(i, j, u.free - 1, u.dist); } else if (abs(dx) + abs(dy) <= n) { que.emplace_back(i, j, n - 1, u.dist + 1); } } } }
#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...