Submission #410417

# Submission time Handle Problem Language Result Execution time Memory
410417 2021-05-22T16:43:12 Z Tc14 Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 616292 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "walk.h"
using namespace std;
#define ve vector
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 10;
const ll LLINF = (ll)1e18 + 10;

ll min_distance(ve<int> X, ve<int> H, ve<int> L, ve<int> R, ve<int> Y, int s, int g) {

    int n = (int)X.size();
    int m = (int)L.size();

    ve<tuple<int, int, int>> E;
    ve<ve<pii>> S(n);
    ve<pii> P(m, {-1, -1});
    ve<ll> D;
    ve<ve<pair<int, ll>>> G(n);
    priority_queue<pair<ll, int>, ve<pair<ll, int>>, greater<pair<ll, int>>> pq;

    for (int i = 0; i < n; i++) {
        S[i].push_back({i, 0});
        E.push_back({i, 1, -1});
    }

    for (int i = 0; i < m; i++) {
        E.push_back({L[i], 0, i});
        E.push_back({R[i], 2, i});
    }
    sort(E.begin(), E.end());

    set<pii> A;
    for (tuple<int, int, int> e : E) {

        if (get<1>(e) == 0) {
            int j = get<2>(e);
            A.insert({Y[j], j});
        }
        else if (get<1>(e) == 1) {

            int i = get<0>(e);
            for (pii a : A) {
                int j, y;
                tie(y, j) = a;
                if (y > H[i]) break;

                int u = (int)G.size();
                G.push_back({});

                if (P[j].first != -1) {
                    ll w = X[i] - P[j].second;
                    int v = P[j].first;
                    G[u].push_back({v, w});
                    G[v].push_back({u, w});
                }
                P[j] = {u, X[i]};

                S[i].push_back({u, y});
            }

        }
        else {
            int j = get<2>(e);
            A.erase({Y[j], j});
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 1; j < (int)S[i].size(); j++) {
            ll w = S[i][j].second - S[i][j - 1].second;
            int u = S[i][j].first;
            int v = S[i][j - 1].first;
            G[u].push_back({v, w});
            G[v].push_back({u, w});
        }
    }

    D = ve<ll>(G.size(), LLINF);
    pq.push({0, s});

    while (!pq.empty()) {
        int u;
        ll d;
        tie(d, u) = pq.top();
        pq.pop();

        if (D[u] != LLINF) continue;
        D[u] = d;

        for (pair<int, ll> e : G[u]) {
            pq.push({d + e.second, e.first});
        }
    }

    if (D[g] == LLINF) return -1;
    else return D[g];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 746 ms 96460 KB Output is correct
4 Correct 703 ms 113096 KB Output is correct
5 Correct 350 ms 97920 KB Output is correct
6 Correct 323 ms 87844 KB Output is correct
7 Correct 341 ms 98112 KB Output is correct
8 Correct 949 ms 120820 KB Output is correct
9 Correct 420 ms 96428 KB Output is correct
10 Correct 996 ms 149612 KB Output is correct
11 Correct 379 ms 58224 KB Output is correct
12 Correct 203 ms 46348 KB Output is correct
13 Correct 824 ms 133812 KB Output is correct
14 Correct 198 ms 43616 KB Output is correct
15 Correct 197 ms 44240 KB Output is correct
16 Correct 216 ms 45608 KB Output is correct
17 Correct 215 ms 44096 KB Output is correct
18 Correct 279 ms 46692 KB Output is correct
19 Correct 9 ms 2408 KB Output is correct
20 Correct 97 ms 21952 KB Output is correct
21 Correct 189 ms 42820 KB Output is correct
22 Correct 193 ms 44488 KB Output is correct
23 Correct 359 ms 58960 KB Output is correct
24 Correct 220 ms 44868 KB Output is correct
25 Correct 212 ms 43920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 18552 KB Output is correct
2 Execution timed out 4090 ms 616292 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 18552 KB Output is correct
2 Execution timed out 4090 ms 616292 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 420 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 746 ms 96460 KB Output is correct
21 Correct 703 ms 113096 KB Output is correct
22 Correct 350 ms 97920 KB Output is correct
23 Correct 323 ms 87844 KB Output is correct
24 Correct 341 ms 98112 KB Output is correct
25 Correct 949 ms 120820 KB Output is correct
26 Correct 420 ms 96428 KB Output is correct
27 Correct 996 ms 149612 KB Output is correct
28 Correct 379 ms 58224 KB Output is correct
29 Correct 203 ms 46348 KB Output is correct
30 Correct 824 ms 133812 KB Output is correct
31 Correct 198 ms 43616 KB Output is correct
32 Correct 197 ms 44240 KB Output is correct
33 Correct 216 ms 45608 KB Output is correct
34 Correct 215 ms 44096 KB Output is correct
35 Correct 279 ms 46692 KB Output is correct
36 Correct 9 ms 2408 KB Output is correct
37 Correct 97 ms 21952 KB Output is correct
38 Correct 189 ms 42820 KB Output is correct
39 Correct 193 ms 44488 KB Output is correct
40 Correct 359 ms 58960 KB Output is correct
41 Correct 220 ms 44868 KB Output is correct
42 Correct 212 ms 43920 KB Output is correct
43 Correct 95 ms 18552 KB Output is correct
44 Execution timed out 4090 ms 616292 KB Time limit exceeded
45 Halted 0 ms 0 KB -