Submission #1040051

#TimeUsernameProblemLanguageResultExecution timeMemory
1040051TAhmed33Maze (JOI23_ho_t3)C++98
19 / 100
2084 ms1616 KiB
#include <bits/stdc++.h> using namespace std; int n, m, x; int sr, sc, gr, gc; vector <vector <char>> a; priority_queue <array <int, 3>, vector <array <int, 3>>, greater <>> 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({0, sr, sc}); while (!pq.empty()) { auto k = pq.top(); pq.pop(); if (k[0] > dist[k[1]][k[2]]) { continue; } for (int j = 0; j < n; j++) { for (int l = 0; l < m; l++) { if (abs(j - k[1]) <= x && abs(l - k[2]) <= x) { 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({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({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...