Submission #599775

# Submission time Handle Problem Language Result Execution time Memory
599775 2022-07-19T20:49:26 Z Johann Sky Walking (IOI19_walk) C++14
24 / 100
4000 ms 850380 KB
// #include "walk.h"
#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 = 1e18;

ll djikstra(vvpii & adj, int s, int g) {
    int n = sz(adj);
    vi dist(n, INF);
    priority_queue<pii, vpii, greater<pii>> q;
    q.push({ 0, s });
    while (!q.empty()) {
        ll v,d;
        tie(d,v) = q.top(); q.pop();
        if (dist[v] <= d) continue;
        dist[v] = d;
        for (pii e : adj[v]) {
            ll u,dd;
            tie(u,dd) = e;
            if (dist[u] == INF) q.push({ d + dd, u });
        }
    }
    return (dist[g] == INF) ? -1 : dist[g];
}

ll min_distance(vpii & B, vtiii &S, int s, int g) {

    int n = sz(B);
    int m = sz(S);
    set<int> bu; // Häuser nach Positions
    vpii BnachH(n); // häuser nach Höhe
    F0R(i,n) bu.insert(i);
    F0R(i,n) BnachH[i] = { B[i].second, i };
    sort(all(BnachH), [&](pii & a, pii & b) { return a > b; });
    sort(all(S), [&](tiii &a, tiii &b) { return get<2>(a) < get<2>(b); }); // Segmente nach Höhe

    vector<set<int>> heightsOnBuildings(n);
    F0R(i,n) heightsOnBuildings[i].insert(0), heightsOnBuildings[i].insert(B[i].second);
    vvi buildingsOnSegment(m);

    F0R(i, m) {
        tiii seg = S[i];
        int l, r, y;
        tie(l, r, y) = seg;
        while (BnachH.back().first < y) {
            int idx = BnachH.back().second;
            bu.erase(idx);
            BnachH.pop_back();
        }
        for (auto it = bu.lower_bound(l); it != bu.end() && *it <= r; ++it) {
            int idx = *it;
            heightsOnBuildings[idx].insert(y);
            buildingsOnSegment[i].push_back(idx);
        }
    }

    vvpii adj;
    map<pii, int> nodes;
    int idx = 0;
    F0R(i,n) {
        int last = -1, lastH = -1;
        for (int y : heightsOnBuildings[i]) {
            nodes[{i, y}] = idx;
            adj.push_back(vpii());
            if (last != -1) {
                adj[last].push_back({ idx, abs(y - lastH) });
                adj[idx].push_back({ last, abs(y - lastH) });
            }
            last = idx;
            lastH = y;
            idx++;
        }
    }

    F0R(i,m) {
        int l,r,y;
        tie(l,r,y) = S[i];

        int last = -1;
        for (int b : buildingsOnSegment[i]) {
            if (last != -1) {
                int dist = abs(B[last].first - B[b].first);
                int i1 = nodes[{ b, y }], i2 = nodes[{ last, y }];
                adj[i1].push_back({ i2, dist });
                adj[i2].push_back({ i1, dist });
            }
            last = b;
        }
    }

    return djikstra(adj, nodes[{s,0}], nodes[{g,0}]);
}

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);
    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 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 468 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 552 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 1627 ms 207220 KB Output is correct
4 Correct 1589 ms 248712 KB Output is correct
5 Correct 1081 ms 218032 KB Output is correct
6 Correct 959 ms 194048 KB Output is correct
7 Correct 1088 ms 217940 KB Output is correct
8 Correct 2197 ms 263508 KB Output is correct
9 Correct 1348 ms 211712 KB Output is correct
10 Correct 2179 ms 333552 KB Output is correct
11 Correct 821 ms 124012 KB Output is correct
12 Correct 635 ms 110044 KB Output is correct
13 Correct 1793 ms 295976 KB Output is correct
14 Correct 367 ms 92516 KB Output is correct
15 Correct 400 ms 82224 KB Output is correct
16 Correct 411 ms 82092 KB Output is correct
17 Correct 424 ms 79672 KB Output is correct
18 Correct 362 ms 110180 KB Output is correct
19 Correct 10 ms 4216 KB Output is correct
20 Correct 120 ms 38588 KB Output is correct
21 Correct 434 ms 78084 KB Output is correct
22 Correct 476 ms 79976 KB Output is correct
23 Correct 365 ms 97244 KB Output is correct
24 Correct 423 ms 81028 KB Output is correct
25 Correct 479 ms 79344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 23836 KB Output is correct
2 Execution timed out 4104 ms 850380 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 116 ms 23836 KB Output is correct
2 Execution timed out 4104 ms 850380 KB Time limit exceeded
3 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 552 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1627 ms 207220 KB Output is correct
21 Correct 1589 ms 248712 KB Output is correct
22 Correct 1081 ms 218032 KB Output is correct
23 Correct 959 ms 194048 KB Output is correct
24 Correct 1088 ms 217940 KB Output is correct
25 Correct 2197 ms 263508 KB Output is correct
26 Correct 1348 ms 211712 KB Output is correct
27 Correct 2179 ms 333552 KB Output is correct
28 Correct 821 ms 124012 KB Output is correct
29 Correct 635 ms 110044 KB Output is correct
30 Correct 1793 ms 295976 KB Output is correct
31 Correct 367 ms 92516 KB Output is correct
32 Correct 400 ms 82224 KB Output is correct
33 Correct 411 ms 82092 KB Output is correct
34 Correct 424 ms 79672 KB Output is correct
35 Correct 362 ms 110180 KB Output is correct
36 Correct 10 ms 4216 KB Output is correct
37 Correct 120 ms 38588 KB Output is correct
38 Correct 434 ms 78084 KB Output is correct
39 Correct 476 ms 79976 KB Output is correct
40 Correct 365 ms 97244 KB Output is correct
41 Correct 423 ms 81028 KB Output is correct
42 Correct 479 ms 79344 KB Output is correct
43 Correct 116 ms 23836 KB Output is correct
44 Execution timed out 4104 ms 850380 KB Time limit exceeded
45 Halted 0 ms 0 KB -