Submission #1040055

#TimeUsernameProblemLanguageResultExecution timeMemory
1040055TAhmed33Maze (JOI23_ho_t3)C++98
27 / 100
2091 ms36372 KiB
#include <bits/stdc++.h> using namespace std; int n, m, x; int sr, sc, gr, gc; vector <vector <char>> a; deque <array <int, 3>> pq; vector <vector <int>> dist; int dx[4] = {0, -1, 0, 1}; int dy[4] = {1, 0, -1, 0}; void solve () { cin >> n >> m >> x >> sr >> sc >> gr >> gc; a.resize(n); dist.resize(n); for (auto &i : dist) { i.resize(m); for (auto &j : i) { j = 1e9; } } for (auto &i : a) { i.resize(m); for (auto &j : i) { cin >> j; } } sr--; sc--; gr--; gc--; dist[sr][sc] = 0; pq.push_back({0, sr, sc}); while (!pq.empty()) { auto k = pq.front(); pq.pop_front(); if (k[0] > dist[k[1]][k[2]]) { continue; } for (int g = -x; g <= x; g++) { for (int h = -x; h <= x; h++) { int j = k[1] + g, l = k[2] + h; if (j < 0 || j >= n || l < 0 || l >= m) { continue; } bool flag = abs(j - k[1]) < x; flag |= abs(l - k[2]) < x; if (!flag) continue; if (k[0] + 1 < dist[j][l]) { dist[j][l] = k[0] + 1; pq.push_back({dist[j][l], j, l}); } } } for (int i = 0; i < 4; i++) { int x = k[1] + dx[i], y = k[2] + dy[i]; if (x >= 0 && x < n && y >= 0 && y < m) { if (a[x][y] != '#') { if (dist[x][y] > k[0]) { dist[x][y] = k[0]; pq.push_front({dist[x][y], x, y}); } } } } } cout << dist[gr][gc] << '\n'; } signed main () { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) 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...