Submission #937670

# Submission time Handle Problem Language Result Execution time Memory
937670 2024-03-04T10:25:37 Z zwezdinv Maze (JOI23_ho_t3) C++17
8 / 100
121 ms 26892 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();
                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);
                        } else {
                                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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 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 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 2 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 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 10 ms 704 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 12 ms 616 KB Output is correct
33 Correct 10 ms 600 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 11 ms 1112 KB Output is correct
37 Correct 10 ms 860 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 101 ms 2140 KB Output is correct
40 Correct 6 ms 604 KB Output is correct
41 Correct 4 ms 676 KB Output is correct
42 Correct 16 ms 760 KB Output is correct
43 Correct 12 ms 604 KB Output is correct
44 Correct 23 ms 1116 KB Output is correct
45 Correct 28 ms 1272 KB Output is correct
46 Correct 56 ms 26892 KB Output is correct
47 Correct 121 ms 2384 KB Output is correct
48 Correct 72 ms 2288 KB Output is correct
49 Correct 34 ms 3164 KB Output is correct
50 Correct 36 ms 3164 KB Output is correct
51 Correct 83 ms 4164 KB Output is correct
52 Correct 69 ms 3056 KB Output is correct
53 Correct 81 ms 2576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 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 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 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 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 2 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 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 10 ms 704 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 12 ms 616 KB Output is correct
33 Correct 10 ms 600 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 11 ms 1112 KB Output is correct
37 Correct 10 ms 860 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 101 ms 2140 KB Output is correct
40 Correct 6 ms 604 KB Output is correct
41 Correct 4 ms 676 KB Output is correct
42 Correct 16 ms 760 KB Output is correct
43 Correct 12 ms 604 KB Output is correct
44 Correct 23 ms 1116 KB Output is correct
45 Correct 28 ms 1272 KB Output is correct
46 Correct 56 ms 26892 KB Output is correct
47 Correct 121 ms 2384 KB Output is correct
48 Correct 72 ms 2288 KB Output is correct
49 Correct 34 ms 3164 KB Output is correct
50 Correct 36 ms 3164 KB Output is correct
51 Correct 83 ms 4164 KB Output is correct
52 Correct 69 ms 3056 KB Output is correct
53 Correct 81 ms 2576 KB Output is correct
54 Incorrect 0 ms 344 KB Output isn't correct
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 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 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 2 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 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 10 ms 704 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 12 ms 616 KB Output is correct
33 Correct 10 ms 600 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 11 ms 1112 KB Output is correct
37 Correct 10 ms 860 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 101 ms 2140 KB Output is correct
40 Correct 6 ms 604 KB Output is correct
41 Correct 4 ms 676 KB Output is correct
42 Correct 16 ms 760 KB Output is correct
43 Correct 12 ms 604 KB Output is correct
44 Correct 23 ms 1116 KB Output is correct
45 Correct 28 ms 1272 KB Output is correct
46 Correct 56 ms 26892 KB Output is correct
47 Correct 121 ms 2384 KB Output is correct
48 Correct 72 ms 2288 KB Output is correct
49 Correct 34 ms 3164 KB Output is correct
50 Correct 36 ms 3164 KB Output is correct
51 Correct 83 ms 4164 KB Output is correct
52 Correct 69 ms 3056 KB Output is correct
53 Correct 81 ms 2576 KB Output is correct
54 Incorrect 0 ms 344 KB Output isn't correct
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 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 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 2 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 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 10 ms 704 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 12 ms 616 KB Output is correct
33 Correct 10 ms 600 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 11 ms 1112 KB Output is correct
37 Correct 10 ms 860 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 101 ms 2140 KB Output is correct
40 Correct 6 ms 604 KB Output is correct
41 Correct 4 ms 676 KB Output is correct
42 Correct 16 ms 760 KB Output is correct
43 Correct 12 ms 604 KB Output is correct
44 Correct 23 ms 1116 KB Output is correct
45 Correct 28 ms 1272 KB Output is correct
46 Correct 56 ms 26892 KB Output is correct
47 Correct 121 ms 2384 KB Output is correct
48 Correct 72 ms 2288 KB Output is correct
49 Correct 34 ms 3164 KB Output is correct
50 Correct 36 ms 3164 KB Output is correct
51 Correct 83 ms 4164 KB Output is correct
52 Correct 69 ms 3056 KB Output is correct
53 Correct 81 ms 2576 KB Output is correct
54 Incorrect 0 ms 344 KB Output isn't correct
55 Halted 0 ms 0 KB -