# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
937678 |
2024-03-04T10:32:24 Z |
zwezdinv |
Maze (JOI23_ho_t3) |
C++17 |
|
125 ms |
79496 KB |
#include <bits/stdc++.h>
struct node {
int x, y, free, dist;
node() = default;
node(int x, int y, int free, int dist) : x(x), y(y), free(free), dist(dist) {}
};
std::vector<std::pair<int, int>> dir1 = {
{0, 1},
{0, -1},
{1, 0},
{-1, 0}
};
std::vector<std::pair<int, int>> dir2 = {
{1, 1},
{1, -1},
{-1, 1},
{-1, -1}
};
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int r, c, n;
std::cin >> r >> c >> n;
int sx, sy, fx, fy;
std::cin >> sx >> sy >> fx >> fy;
--sx, --sy, --fx, --fy;
std::vector a(r, std::vector(c, '#'));
for (auto& i : a) {
for (auto& j : i) {
std::cin >> j;
}
}
std::deque<node> que;
std::vector used(r, std::vector(c, false));
que.emplace_back(sx, sy, 0, 0);
while (que.size()) {
node u = que.front();
assert(u.free >= 0);
que.pop_front();
if (u.x == fx && u.y == fy) {
std::cout << u.dist << '\n';
break;
}
if (used[u.x][u.y]) continue;
used[u.x][u.y] = true;
for (auto [dx, dy] : dir1) {
int i = u.x + dx, j = u.y + dy;
if (i < 0 || i >= r || j < 0 || j >= c) continue;
if (a[i][j] == '.') {
que.emplace_front(i, j, std::max(u.free - 1, 0), u.dist);
}
if (u.free == 0) {
que.emplace_back(i, j, n - 1, u.dist + 1);
} else {
que.emplace_front(i, j, u.free - 1, u.dist);
}
}
for (auto [dx, dy] : dir2) {
int i = u.x + dx, j = u.y + dy;
if (i < 0 || i >= r || j < 0 || j >= c) continue;
if (u.free >= 2) {
que.emplace_front(i, j, u.free - 1, u.dist);
} else if (n >= 2) {
que.emplace_back(i, j, n - 1, u.dist + 1);
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
1372 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
4 ms |
524 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
12 ms |
680 KB |
Output is correct |
30 |
Correct |
4 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
3612 KB |
Output is correct |
32 |
Correct |
14 ms |
844 KB |
Output is correct |
33 |
Correct |
9 ms |
676 KB |
Output is correct |
34 |
Correct |
8 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
1448 KB |
Output is correct |
37 |
Correct |
11 ms |
1168 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
102 ms |
2292 KB |
Output is correct |
40 |
Correct |
6 ms |
604 KB |
Output is correct |
41 |
Correct |
6 ms |
676 KB |
Output is correct |
42 |
Correct |
17 ms |
604 KB |
Output is correct |
43 |
Correct |
12 ms |
604 KB |
Output is correct |
44 |
Correct |
29 ms |
1324 KB |
Output is correct |
45 |
Correct |
26 ms |
1368 KB |
Output is correct |
46 |
Correct |
101 ms |
79496 KB |
Output is correct |
47 |
Correct |
125 ms |
2544 KB |
Output is correct |
48 |
Correct |
71 ms |
2316 KB |
Output is correct |
49 |
Correct |
52 ms |
3164 KB |
Output is correct |
50 |
Correct |
38 ms |
3164 KB |
Output is correct |
51 |
Correct |
98 ms |
5972 KB |
Output is correct |
52 |
Correct |
71 ms |
3416 KB |
Output is correct |
53 |
Correct |
79 ms |
2584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 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 |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 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 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
1372 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
4 ms |
524 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
12 ms |
680 KB |
Output is correct |
30 |
Correct |
4 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
3612 KB |
Output is correct |
32 |
Correct |
14 ms |
844 KB |
Output is correct |
33 |
Correct |
9 ms |
676 KB |
Output is correct |
34 |
Correct |
8 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
1448 KB |
Output is correct |
37 |
Correct |
11 ms |
1168 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
102 ms |
2292 KB |
Output is correct |
40 |
Correct |
6 ms |
604 KB |
Output is correct |
41 |
Correct |
6 ms |
676 KB |
Output is correct |
42 |
Correct |
17 ms |
604 KB |
Output is correct |
43 |
Correct |
12 ms |
604 KB |
Output is correct |
44 |
Correct |
29 ms |
1324 KB |
Output is correct |
45 |
Correct |
26 ms |
1368 KB |
Output is correct |
46 |
Correct |
101 ms |
79496 KB |
Output is correct |
47 |
Correct |
125 ms |
2544 KB |
Output is correct |
48 |
Correct |
71 ms |
2316 KB |
Output is correct |
49 |
Correct |
52 ms |
3164 KB |
Output is correct |
50 |
Correct |
38 ms |
3164 KB |
Output is correct |
51 |
Correct |
98 ms |
5972 KB |
Output is correct |
52 |
Correct |
71 ms |
3416 KB |
Output is correct |
53 |
Correct |
79 ms |
2584 KB |
Output is correct |
54 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
1372 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
4 ms |
524 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
12 ms |
680 KB |
Output is correct |
30 |
Correct |
4 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
3612 KB |
Output is correct |
32 |
Correct |
14 ms |
844 KB |
Output is correct |
33 |
Correct |
9 ms |
676 KB |
Output is correct |
34 |
Correct |
8 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
1448 KB |
Output is correct |
37 |
Correct |
11 ms |
1168 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
102 ms |
2292 KB |
Output is correct |
40 |
Correct |
6 ms |
604 KB |
Output is correct |
41 |
Correct |
6 ms |
676 KB |
Output is correct |
42 |
Correct |
17 ms |
604 KB |
Output is correct |
43 |
Correct |
12 ms |
604 KB |
Output is correct |
44 |
Correct |
29 ms |
1324 KB |
Output is correct |
45 |
Correct |
26 ms |
1368 KB |
Output is correct |
46 |
Correct |
101 ms |
79496 KB |
Output is correct |
47 |
Correct |
125 ms |
2544 KB |
Output is correct |
48 |
Correct |
71 ms |
2316 KB |
Output is correct |
49 |
Correct |
52 ms |
3164 KB |
Output is correct |
50 |
Correct |
38 ms |
3164 KB |
Output is correct |
51 |
Correct |
98 ms |
5972 KB |
Output is correct |
52 |
Correct |
71 ms |
3416 KB |
Output is correct |
53 |
Correct |
79 ms |
2584 KB |
Output is correct |
54 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
1372 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
4 ms |
524 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
12 ms |
680 KB |
Output is correct |
30 |
Correct |
4 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
3612 KB |
Output is correct |
32 |
Correct |
14 ms |
844 KB |
Output is correct |
33 |
Correct |
9 ms |
676 KB |
Output is correct |
34 |
Correct |
8 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
1448 KB |
Output is correct |
37 |
Correct |
11 ms |
1168 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
102 ms |
2292 KB |
Output is correct |
40 |
Correct |
6 ms |
604 KB |
Output is correct |
41 |
Correct |
6 ms |
676 KB |
Output is correct |
42 |
Correct |
17 ms |
604 KB |
Output is correct |
43 |
Correct |
12 ms |
604 KB |
Output is correct |
44 |
Correct |
29 ms |
1324 KB |
Output is correct |
45 |
Correct |
26 ms |
1368 KB |
Output is correct |
46 |
Correct |
101 ms |
79496 KB |
Output is correct |
47 |
Correct |
125 ms |
2544 KB |
Output is correct |
48 |
Correct |
71 ms |
2316 KB |
Output is correct |
49 |
Correct |
52 ms |
3164 KB |
Output is correct |
50 |
Correct |
38 ms |
3164 KB |
Output is correct |
51 |
Correct |
98 ms |
5972 KB |
Output is correct |
52 |
Correct |
71 ms |
3416 KB |
Output is correct |
53 |
Correct |
79 ms |
2584 KB |
Output is correct |
54 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |