Submission #1040059

#TimeUsernameProblemLanguageResultExecution timeMemory
1040059TAhmed33Maze (JOI23_ho_t3)C++98
27 / 100
2098 ms35244 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}; vector <vector <bool>> vis; void solve () { cin >> n >> m >> x >> sr >> sc >> gr >> gc; dist.resize(n, vector <int> (m, int(1e9))); a.resize(n, vector <char> (m)); vis.resize(n, vector <bool> (m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][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...