Submission #801542

# Submission time Handle Problem Language Result Execution time Memory
801542 2023-08-02T06:32:36 Z resting Sky Walking (IOI19_walk) C++17
100 / 100
3081 ms 144392 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int inf = 1e9;

long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
    int n = x.size(), m = l.size();
    vector<pair<int, pair<int, int>>> a, b, c;
    for (int i = 0; i < m; i++) a.push_back({ y[i], {l[i], r[i]} });
    sort(a.begin(), a.end());
    vector<pair<int, int>> bld;
    for (int i = 0; i < n; i++) bld.push_back({ h[i], i });
    bld.push_back({ 0, -1 }); // just for the sake of it
    sort(bld.begin(), bld.end());
#define uwu(s, sign, mn, st)\
    {\
        int rght = st;\
        for (int i = n - 1; i >= 0; i--) {\
            while (a.size() && a.back().first > bld[i].first) {\
                if (a.back().second.first < rght && a.back().second.second > rght) {\
                    b.push_back({ a.back().first, {a.back().second.first, rght } });\
                    b.push_back({ a.back().first, {rght, a.back().second.second } });\
                }\
                else b.push_back(a.back());\
                a.pop_back();\
            }\
            if (bld[i].second sign s)\
                rght = mn(rght, bld[i].second);\
        }\
        swap(a, b); reverse(a.begin(), a.end());\
    }

    uwu(s, >= , min, inf);
    uwu(s, <= , max, -inf);
    uwu(g, >= , min, inf);
    uwu(g, <= , max, -inf);
    reverse(a.begin(), a.end());
    set<pair<int, int>> pts; // set of points
    map<pair<int, int>, vector<pair<int, int>>> adj;
    auto edge = [&](pair<int, int> a, pair<int, int> b) {
        adj[a].push_back(b); adj[b].push_back(a);
    };
    auto dist = [&](pair<int, int> a, pair<int, int> b) -> ll {
        return (ll)(abs(x[a.first] - x[b.first]) + abs(a.second - b.second));
    };
    for (auto& x : a) {
        int prev = x.second.first;
        auto pt = pts.lower_bound({ x.second.first, 0 });
        while (pt != pts.end() && pt->first <= x.second.second) {
            edge({ pt->first, x.first }, { prev, x.first });
            edge({ pt->first, x.first }, { pt->first, pt->second });
            prev = pt->first;
            pts.erase(pt++);
        }
        edge({ x.second.second, x.first }, { prev, x.first });
        pts.insert({ x.second.first, x.first });
        pts.insert({ x.second.second, x.first });
    }
    for (auto& x : pts) {
        edge({ x.first, x.second }, { x.first, 0 });
    }

    map<pair<int, int>, ll> dst;
    set<pair<ll, pair<int, int>>> q;
    q.insert({ 1, {s, 0} });
    while (!q.empty()) {
        auto t = *q.begin();
        q.erase(q.begin());
        if (dst[t.second]) continue;
        dst[t.second] = t.first;
        for (auto& x : adj[t.second]) {
            q.insert({ dist(t.second, x) + t.first,  x });
        }
    }
    return dst[{g, 0}] - 1;
}
# 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 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
# 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 Correct 1154 ms 68376 KB Output is correct
4 Correct 856 ms 78368 KB Output is correct
5 Correct 342 ms 43936 KB Output is correct
6 Correct 365 ms 44188 KB Output is correct
7 Correct 346 ms 44188 KB Output is correct
8 Correct 1086 ms 72440 KB Output is correct
9 Correct 515 ms 57540 KB Output is correct
10 Correct 862 ms 78544 KB Output is correct
11 Correct 762 ms 67128 KB Output is correct
12 Correct 562 ms 74028 KB Output is correct
13 Correct 799 ms 80196 KB Output is correct
14 Correct 303 ms 50204 KB Output is correct
15 Correct 466 ms 73376 KB Output is correct
16 Correct 408 ms 70052 KB Output is correct
17 Correct 417 ms 67060 KB Output is correct
18 Correct 516 ms 59984 KB Output is correct
19 Correct 15 ms 3828 KB Output is correct
20 Correct 227 ms 35636 KB Output is correct
21 Correct 363 ms 67432 KB Output is correct
22 Correct 503 ms 73100 KB Output is correct
23 Correct 601 ms 76800 KB Output is correct
24 Correct 482 ms 71056 KB Output is correct
25 Correct 443 ms 66880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 18900 KB Output is correct
2 Correct 1398 ms 76152 KB Output is correct
3 Correct 1405 ms 77304 KB Output is correct
4 Correct 1753 ms 79612 KB Output is correct
5 Correct 1987 ms 83124 KB Output is correct
6 Correct 1888 ms 84164 KB Output is correct
7 Correct 597 ms 41852 KB Output is correct
8 Correct 594 ms 70180 KB Output is correct
9 Correct 1904 ms 88676 KB Output is correct
10 Correct 583 ms 68204 KB Output is correct
11 Correct 14 ms 1824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 18900 KB Output is correct
2 Correct 1398 ms 76152 KB Output is correct
3 Correct 1405 ms 77304 KB Output is correct
4 Correct 1753 ms 79612 KB Output is correct
5 Correct 1987 ms 83124 KB Output is correct
6 Correct 1888 ms 84164 KB Output is correct
7 Correct 597 ms 41852 KB Output is correct
8 Correct 594 ms 70180 KB Output is correct
9 Correct 1904 ms 88676 KB Output is correct
10 Correct 583 ms 68204 KB Output is correct
11 Correct 14 ms 1824 KB Output is correct
12 Correct 1463 ms 79060 KB Output is correct
13 Correct 510 ms 58308 KB Output is correct
14 Correct 1715 ms 86092 KB Output is correct
15 Correct 866 ms 77108 KB Output is correct
16 Correct 974 ms 74760 KB Output is correct
17 Correct 1078 ms 83624 KB Output is correct
18 Correct 859 ms 77220 KB Output is correct
19 Correct 969 ms 74528 KB Output is correct
20 Correct 651 ms 43580 KB Output is correct
21 Correct 30 ms 5280 KB Output is correct
22 Correct 426 ms 52112 KB Output is correct
23 Correct 376 ms 49360 KB Output is correct
24 Correct 425 ms 48364 KB Output is correct
25 Correct 383 ms 47272 KB Output is correct
26 Correct 361 ms 50252 KB Output is correct
27 Correct 1876 ms 84808 KB Output is correct
28 Correct 522 ms 58164 KB Output is correct
29 Correct 1552 ms 80464 KB Output is correct
30 Correct 597 ms 44616 KB Output is correct
31 Correct 1467 ms 78120 KB Output is correct
32 Correct 419 ms 65660 KB Output is correct
33 Correct 491 ms 68584 KB Output is correct
34 Correct 515 ms 70856 KB Output is correct
35 Correct 509 ms 72588 KB Output is correct
36 Correct 481 ms 68824 KB Output is correct
37 Correct 370 ms 67548 KB Output is correct
38 Correct 484 ms 73136 KB Output is correct
39 Correct 581 ms 76764 KB Output is correct
40 Correct 432 ms 71160 KB Output is correct
41 Correct 426 ms 67008 KB Output is correct
# 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 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1154 ms 68376 KB Output is correct
21 Correct 856 ms 78368 KB Output is correct
22 Correct 342 ms 43936 KB Output is correct
23 Correct 365 ms 44188 KB Output is correct
24 Correct 346 ms 44188 KB Output is correct
25 Correct 1086 ms 72440 KB Output is correct
26 Correct 515 ms 57540 KB Output is correct
27 Correct 862 ms 78544 KB Output is correct
28 Correct 762 ms 67128 KB Output is correct
29 Correct 562 ms 74028 KB Output is correct
30 Correct 799 ms 80196 KB Output is correct
31 Correct 303 ms 50204 KB Output is correct
32 Correct 466 ms 73376 KB Output is correct
33 Correct 408 ms 70052 KB Output is correct
34 Correct 417 ms 67060 KB Output is correct
35 Correct 516 ms 59984 KB Output is correct
36 Correct 15 ms 3828 KB Output is correct
37 Correct 227 ms 35636 KB Output is correct
38 Correct 363 ms 67432 KB Output is correct
39 Correct 503 ms 73100 KB Output is correct
40 Correct 601 ms 76800 KB Output is correct
41 Correct 482 ms 71056 KB Output is correct
42 Correct 443 ms 66880 KB Output is correct
43 Correct 133 ms 18900 KB Output is correct
44 Correct 1398 ms 76152 KB Output is correct
45 Correct 1405 ms 77304 KB Output is correct
46 Correct 1753 ms 79612 KB Output is correct
47 Correct 1987 ms 83124 KB Output is correct
48 Correct 1888 ms 84164 KB Output is correct
49 Correct 597 ms 41852 KB Output is correct
50 Correct 594 ms 70180 KB Output is correct
51 Correct 1904 ms 88676 KB Output is correct
52 Correct 583 ms 68204 KB Output is correct
53 Correct 14 ms 1824 KB Output is correct
54 Correct 1463 ms 79060 KB Output is correct
55 Correct 510 ms 58308 KB Output is correct
56 Correct 1715 ms 86092 KB Output is correct
57 Correct 866 ms 77108 KB Output is correct
58 Correct 974 ms 74760 KB Output is correct
59 Correct 1078 ms 83624 KB Output is correct
60 Correct 859 ms 77220 KB Output is correct
61 Correct 969 ms 74528 KB Output is correct
62 Correct 651 ms 43580 KB Output is correct
63 Correct 30 ms 5280 KB Output is correct
64 Correct 426 ms 52112 KB Output is correct
65 Correct 376 ms 49360 KB Output is correct
66 Correct 425 ms 48364 KB Output is correct
67 Correct 383 ms 47272 KB Output is correct
68 Correct 361 ms 50252 KB Output is correct
69 Correct 1876 ms 84808 KB Output is correct
70 Correct 522 ms 58164 KB Output is correct
71 Correct 1552 ms 80464 KB Output is correct
72 Correct 597 ms 44616 KB Output is correct
73 Correct 1467 ms 78120 KB Output is correct
74 Correct 419 ms 65660 KB Output is correct
75 Correct 491 ms 68584 KB Output is correct
76 Correct 515 ms 70856 KB Output is correct
77 Correct 509 ms 72588 KB Output is correct
78 Correct 481 ms 68824 KB Output is correct
79 Correct 370 ms 67548 KB Output is correct
80 Correct 484 ms 73136 KB Output is correct
81 Correct 581 ms 76764 KB Output is correct
82 Correct 432 ms 71160 KB Output is correct
83 Correct 426 ms 67008 KB Output is correct
84 Correct 98 ms 16068 KB Output is correct
85 Correct 1420 ms 83036 KB Output is correct
86 Correct 2298 ms 112584 KB Output is correct
87 Correct 61 ms 11700 KB Output is correct
88 Correct 70 ms 11308 KB Output is correct
89 Correct 58 ms 11604 KB Output is correct
90 Correct 29 ms 5600 KB Output is correct
91 Correct 2 ms 340 KB Output is correct
92 Correct 24 ms 3360 KB Output is correct
93 Correct 392 ms 31640 KB Output is correct
94 Correct 34 ms 5712 KB Output is correct
95 Correct 491 ms 58144 KB Output is correct
96 Correct 363 ms 49856 KB Output is correct
97 Correct 323 ms 48200 KB Output is correct
98 Correct 375 ms 47284 KB Output is correct
99 Correct 3081 ms 144392 KB Output is correct
100 Correct 1495 ms 83720 KB Output is correct
101 Correct 1858 ms 101560 KB Output is correct
102 Correct 565 ms 44868 KB Output is correct
103 Correct 427 ms 65608 KB Output is correct
104 Correct 426 ms 68428 KB Output is correct
105 Correct 470 ms 67156 KB Output is correct
106 Correct 472 ms 68640 KB Output is correct
107 Correct 519 ms 71900 KB Output is correct
108 Correct 54 ms 6780 KB Output is correct
109 Correct 1128 ms 68648 KB Output is correct
110 Correct 633 ms 63784 KB Output is correct
111 Correct 477 ms 59388 KB Output is correct
112 Correct 526 ms 69528 KB Output is correct
113 Correct 519 ms 68736 KB Output is correct