Submission #723914

# Submission time Handle Problem Language Result Execution time Memory
723914 2023-04-14T12:50:48 Z piOOE Escape Route (JOI21_escape_route) C++17
0 / 100
1125 ms 113368 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) {
    constexpr ll inf = 3e18;
    vector<ll> answer(q, inf);
    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);
    }

    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)), dto(n, vector<ll>(n));

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

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

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

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

    for (int i = 0; i < m; ++i) {
        dp[0][i] = dijkstra(A[i], C[i] - L[i]);
        dp[1][i] = dijkstra(B[i], C[i] - L[i]);

        for (int t : {0, 1}) {
            for (int to = 0; to < n; ++to) {
                dp[t][i][to] = inf;
            }
        }
    }

    vector till(n, vector<ll>(m, -inf));

    for (int i = 0; i < m; ++i) {
        int a = A[i], b = B[i];
        ll t = C[i] - L[i];

        auto da = dijkstra(a, t, true);
        auto db = dijkstra(b, t, true);

        for (int x = 0; x < n; ++x) {
            da[x] = t >= da[x] ? t - da[x] : -inf;
            db[x] = t >= db[x] ? t - db[x] : -inf;

            till[x][i] = max(da[x], db[x]);
        }
    }

    for (int i = 0; i < n; ++i) {
        vector<ll> dist(n, inf);
        dist[i] = 0;

        sort(queries[i].begin(), queries[i].end(), [&](int x, int y) {
            return T[x] > T[y];
        });

        vector<pair<ll, int>> ord;

        for (int e = 0; e < m; ++e) {
            if (till[i][e] >= 0) {
                ord.emplace_back(till[i][e], e);
            }
        }

        sort(ord.rbegin(), ord.rend());

        int jj = 0;

        for (auto [t, e] : ord) {
            while (jj < queries[i].size() && T[queries[i][jj]] > t) {
                int j = queries[i][jj++];
                answer[j] = min(answer[j], dist[V[j]]);
            }

            for (int x : {A[e], B[e]}) {
                vector<ll> &d = dp[x == B[e]][e];
                for (int to = 0; to < n; ++to) {
                    dist[to] = min(dist[to], dist[x] + d[to]);
                }
            }
        }

        while (jj < queries[i].size()) {
            int j = queries[i][jj++];
//            if (dist[V[j]] + T[j] < S) {
                answer[j] = min(answer[j], dist[V[j]]);
//            }
        }
    }

    return answer;
}

Compilation message

escape_route.cpp: In function 'std::vector<long long int> calculate_necessary_time(int, int, ll, int, std::vector<int>, std::vector<int>, std::vector<long long int>, std::vector<long long int>, std::vector<int>, std::vector<int>, std::vector<long long int>)':
escape_route.cpp:129:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |             while (jj < queries[i].size() && T[queries[i][jj]] > t) {
      |                    ~~~^~~~~~~~~~~~~~~~~~~
escape_route.cpp:142:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |         while (jj < queries[i].size()) {
      |                ~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 64944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1125 ms 113368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 64944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 64944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 64944 KB Output isn't correct
2 Halted 0 ms 0 KB -