# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1040047 |
2024-07-31T14:41:01 Z |
TAhmed33 |
Maze (JOI23_ho_t3) |
C++ |
|
1 ms |
460 KB |
#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) {
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 time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |