# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
832994 |
2023-08-21T18:37:16 Z |
WLZ |
Maze (JOI23_ho_t3) |
C++17 |
|
1 ms |
352 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "templates/debug.h"
#else
#define debug(...) 0
#endif
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};
const vector<int> dxx = {1, 1, 1, -1, -1, -1, 0, 0};
const vector<int> dyy = {0, 1, -1, 0, 1, -1, -1, 1};
const int INF = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int r, c, n; cin >> r >> c >> n;
int sr, sc, gr, gc; cin >> sr >> sc >> gr >> gc;
sr--; sc--; gr--; gc--;
vector<string> grid(r);
for (int i = 0; i < r; i++) cin >> grid[i];
vector< vector<int> > dist(r, vector<int>(c, INF)); dist[sr][sc] = 0;
priority_queue< tuple<int, int, int>, vector< tuple<int, int, int> >, greater<> > pq; pq.push({0, sr, sc});
while (!pq.empty()) {
int d, x, y;
tie(d, x, y) = pq.top(); pq.pop();
if (d > dist[x][y]) continue;
if (d % (n + 1) < n && d % (n + 1) > 0) {
for (int k = 0; k < 8; k++) {
int nx = x + dxx[k], ny = y + dyy[k];
if (nx < 0 || nx >= r || ny < 0 || ny >= c) continue;
if (d + 1 < dist[nx][ny]) {
dist[nx][ny] = d + 1;
pq.push({dist[nx][ny], nx, ny});
}
}
}
if (d % (n + 1) == 0) {
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (nx < 0 || nx >= r || ny < 0 || ny >= c) continue;
if (d + 1 < dist[nx][ny]) {
dist[nx][ny] = d + 1;
pq.push({dist[nx][ny], nx, ny});
}
}
}
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (nx < 0 || nx >= r || ny < 0 || ny >= c || grid[nx][ny] == '#') continue;
if ((d + n) / (n + 1) * (n + 1) < dist[nx][ny]) {
dist[nx][ny] = (d + n) / (n + 1) * (n + 1);
pq.push({dist[nx][ny], nx, ny});
}
}
}
debug(dist);
cout << (dist[gr][gc] + n) / (n + 1) << '\n';
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:7:20: warning: statement has no effect [-Wunused-value]
7 | #define debug(...) 0
| ^
Main.cpp:60:3: note: in expansion of macro 'debug'
60 | debug(dist);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |