Submission #602273

# Submission time Handle Problem Language Result Execution time Memory
602273 2022-07-22T20:12:12 Z Johann Sky Walking (IOI19_walk) C++14
33 / 100
122 ms 13936 KB
// #include "walk.h"
// bruteForce sub 3
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef tuple<int, int, int> tiii;
typedef vector<bool> vb;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<tiii> vtiii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
#define F0R(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

const int maxN = 10005;
const ll INF = LLONG_MAX;

ll min_distance(vpii &B, vtiii &S, int s, int g) {
    int n = sz(B);
    int m = sz(S);
    map<ll, pii> dp; // höhe : { value, expiryIndex }
    dp[0] = {0, n - 1};

    // Sortierung nach Endpunkt dann von Hinten zum Ziel
    sort(all(S), [&](tiii &a, tiii &b) {
        if (get<1>(a) != get<1>(b)) return get<1>(a) > get<1>(b);
        return get<2>(a) < get<2>(b);
    });

    int i = 0;
    while (i < m) {
        tiii seg = S[i];
        if (sz(dp) == 0) return -1;
        ll l, r, y;
        tie(l, r, y) = seg;
        ll d = INF;
        // Oberhalb:
        auto ito = dp.lower_bound(y);
        if (ito != dp.end()) {
            if (ito->second.second > r) {
                dp.erase(ito);
                continue;
            }
            d = min(d, ito->second.first + abs(ito->first - y));
        }
        // Unterhalb:
        auto itu = dp.lower_bound(y);
        if (itu != dp.begin()) {
            --itu;
            if (itu->second.second > r) {
                dp.erase(itu);
                continue;
            }
            d = min(d, itu->second.first + abs(itu->first - y));
        }
        // Antwort eintragen
        dp[y] = {d, l};
        ++i;
    }
    ll ans = INF;
    for (auto it = dp.begin(); it != dp.end(); ++it) {
        if (it->second.second > s) continue;
        ans = min(ans, it->second.first + it->first);
    }
    if (ans == INF) return -1;
    return ans + B[g].first - B[s].first;
}

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) {
// ll min_distance(vi x, vi h, vi l, vi r, vi y, int s, int g) {
    int n = sz(x), m = sz(l);
    if (g < s) swap(g, s);
    vtiii segs(m);
    vpii B(n);
    F0R(i, n) B[i] = {x[i], h[i]};
    F0R(i, m) segs[i] = {l[i], r[i], y[i]};
    return min_distance(B, segs, s, g);
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2868 KB Output is correct
2 Correct 78 ms 5008 KB Output is correct
3 Correct 83 ms 5324 KB Output is correct
4 Correct 103 ms 8140 KB Output is correct
5 Correct 122 ms 13936 KB Output is correct
6 Correct 113 ms 11448 KB Output is correct
7 Correct 62 ms 5944 KB Output is correct
8 Correct 61 ms 7600 KB Output is correct
9 Correct 104 ms 12072 KB Output is correct
10 Correct 80 ms 10832 KB Output is correct
11 Correct 10 ms 2608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2868 KB Output is correct
2 Correct 78 ms 5008 KB Output is correct
3 Correct 83 ms 5324 KB Output is correct
4 Correct 103 ms 8140 KB Output is correct
5 Correct 122 ms 13936 KB Output is correct
6 Correct 113 ms 11448 KB Output is correct
7 Correct 62 ms 5944 KB Output is correct
8 Correct 61 ms 7600 KB Output is correct
9 Correct 104 ms 12072 KB Output is correct
10 Correct 80 ms 10832 KB Output is correct
11 Correct 10 ms 2608 KB Output is correct
12 Correct 80 ms 5280 KB Output is correct
13 Correct 109 ms 8312 KB Output is correct
14 Correct 121 ms 13904 KB Output is correct
15 Correct 78 ms 9012 KB Output is correct
16 Correct 78 ms 9112 KB Output is correct
17 Correct 84 ms 8996 KB Output is correct
18 Correct 76 ms 9008 KB Output is correct
19 Correct 55 ms 7720 KB Output is correct
20 Correct 65 ms 6196 KB Output is correct
21 Correct 25 ms 4172 KB Output is correct
22 Correct 73 ms 7244 KB Output is correct
23 Correct 73 ms 7352 KB Output is correct
24 Correct 72 ms 8624 KB Output is correct
25 Correct 70 ms 7192 KB Output is correct
26 Correct 51 ms 7372 KB Output is correct
27 Correct 110 ms 13376 KB Output is correct
28 Correct 84 ms 7752 KB Output is correct
29 Correct 110 ms 11580 KB Output is correct
30 Correct 51 ms 6024 KB Output is correct
31 Correct 105 ms 12192 KB Output is correct
32 Correct 66 ms 8812 KB Output is correct
33 Correct 75 ms 9196 KB Output is correct
34 Correct 80 ms 9260 KB Output is correct
35 Correct 79 ms 7984 KB Output is correct
36 Correct 55 ms 7428 KB Output is correct
37 Correct 51 ms 9036 KB Output is correct
38 Correct 56 ms 10060 KB Output is correct
39 Correct 114 ms 12852 KB Output is correct
40 Correct 54 ms 9932 KB Output is correct
41 Correct 50 ms 9032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -