Submission #723424

# Submission time Handle Problem Language Result Execution time Memory
723424 2023-04-13T19:15:25 Z piOOE Escape Route (JOI21_escape_route) C++17
0 / 100
1103 ms 220016 KB
#include "escape_route.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<ll> calculate_necessary_time(int n, int m, ll S, int q, vector<int> A, vector<int> B, vector<ll> L, vector<ll> C,
                                    vector<int> U, vector<int> V, vector<ll> T) {

    vector<ll> answer(q);

    vector<vector<int>> queries(n);

    for (int i = 0; i < q; ++i) {
        queries[U[i]].push_back(i);
    }

    vector<vector<pair<int, int>>> adj(n);

    for (int i = 0; i < m; ++i) {
        adj[A[i]].emplace_back(B[i], i);
        adj[B[i]].emplace_back(A[i], i);
    }

    constexpr ll inf = 3e18;

    auto dijkstra = [&](int source, ll s, bool rev = false) -> vector<ll> {
        vector<ll> dist(n, rev ? -inf : inf);
        dist[source] = s;

        vector<bool> used(n);

        for (int _ = 0; _ < n; ++_) {
            int v = -1;

            for (int i = 0; i < n; ++i) {
                if (!used[i] && (v == -1 || rev ^ (dist[i] < dist[v]))) {
                    v = i;
                }
            }

            used[v] = true;

            for (auto [to, i] : adj[v]) {
                ll d;

                if (rev) {
                    d = min(dist[v], C[i]) - L[i];
                } else {
                    d = L[i] + (dist[v] % S <= C[i] - L[i] ? dist[v] : (dist[v] / S + 1) * S);
                }

                if (rev ^ (dist[to] > d)) {
                    dist[to] = d;
                }
            }
        }

        for (int i = 0; i < n; ++i) {
            dist[i] = rev ? s - dist[i] : dist[i] - s;
        }

        return dist;
    };

    vector from(n, vector<ll>(n));

    for (int i = 0; i < n; ++i) {
        from[i] = dijkstra(i, 0);
    }

    vector dto(n, vector<ll>(n));

    for (int i = 0; i < n; ++i) {
        dto[i] = dijkstra(i, S - 1, true);
    }

    vector dp(m, vector<ll>(n));
    vector<ll> till(m);

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            ll s = j > 0 ? till[j - 1] + 1 : 0;
            vector<ll> d = dijkstra(i, s);
            dp[j] = d;

            ll nxt = inf;

            for (int k = 0; k < m; ++k) {
                ll sub = min(d[A[k]], d[B[k]]) + s;

                if (C[k] - L[k] >= sub) {
                    nxt = min(nxt, C[k] - L[k] - sub);
                }
            }

            till[j] = s + nxt;
        }

        for (int j : queries[i]) {
            ll ans = inf;
            int to = V[j];

            for (int mid = 0; mid < n; ++mid) {
                ll dist = dto[mid][i] >= S - 1 - T[j] ? inf : S - 1 - T[j] + 1 + from[mid][to];
                ans = min(ans, dist);
            }

            int k = lower_bound(till.begin(), till.end(), T[j]) - till.begin();
            ans = min(ans, dp[k][to]);

            answer[j] = ans;
        }
    }

    return answer;
}
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 64980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1103 ms 154848 KB Output is correct
2 Runtime error 255 ms 220016 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 64980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 64980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 64980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -