Submission #723931

# Submission time Handle Problem Language Result Execution time Memory
723931 2023-04-14T13:22:59 Z piOOE Escape Route (JOI21_escape_route) C++17
100 / 100
2638 ms 195508 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);
    }

    A.resize(2 * m), B.resize(2 * m), L.resize(2 * m), C.resize(2 * m);
    for (int i = 0; i < m; ++i) {
        A[i + m] = B[i], B[i + m] = A[i];
        C[i + m] = C[i], L[i + m] = L[i];
    }
    m *= 2;

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

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

    auto dijkstra = [&](int source, ll s) -> vector<ll> {
        vector<ll> dist(n, 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 || dist[i] < dist[v])) {
                    v = i;
                }
            }

            used[v] = true;

            for (int i : adj[v]) {
                int to = B[i];
                ll d = L[i] + (dist[v] % S <= C[i] - L[i] ? dist[v] : (dist[v] / S + 1) * S);
                if (dist[to] > d) {
                    dist[to] = d;
                }
            }
        }

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

        return dist;
    };

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

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

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

        for (int to = 0; to < n; ++to) {
            if (C[e] - L[e] + dp[e][to] >= S) {
                dp[e][to] = inf;
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        sort(adj[i].begin(), adj[i].end(), [&](int x, int y) {
            return C[x] - L[x] > C[y] - L[y];
        });
    };

    for (int i = 0; i < n; ++i) {
        sort(queries[i].begin(), queries[i].end(), [&](int x, int y) {
            return T[x] > T[y];
        });
        int k = 0;

        vector<int> id(n);
        vector<ll> d(m, inf);
        d[i] = 0;

        while (true) {
            pair<ll, int> best{-1, -1};

            for (int x = 0; x < n; ++x) {
                if (id[x] < adj[x].size()) {
                    int e = adj[x][id[x]];
                    best = max(best, {C[e] - L[e] - d[x], x});
                }
            }

            while (k < queries[i].size() && T[queries[i][k]] > best.first) {
                int j = queries[i][k++];
                answer[j] = min(answer[j], d[V[j]]);
                for (int x = 0; x < n; ++x) {
                    if (T[j] + d[x] < S) {
                        answer[j] = min(answer[j], S - T[j] + dist0[x][V[j]]);
                    }
                }
            }

            if (best.first == -1) {
                break;
            }

            int x = best.second;
            int e = adj[x][id[x]++];

            for (int to = 0; to < n; ++to) {
                d[to] = min(d[to], d[x] + dp[e][to]);
            }
        }
    }

    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:98:27: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |                 if (id[x] < adj[x].size()) {
escape_route.cpp:104:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |             while (k < queries[i].size() && T[queries[i][k]] > best.first) {
      |                    ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 65016 KB Output is correct
2 Correct 31 ms 65040 KB Output is correct
3 Correct 62 ms 65016 KB Output is correct
4 Correct 25 ms 65012 KB Output is correct
5 Correct 42 ms 65044 KB Output is correct
6 Correct 27 ms 64980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1458 ms 112076 KB Output is correct
2 Correct 1420 ms 126924 KB Output is correct
3 Correct 1353 ms 122040 KB Output is correct
4 Correct 1435 ms 159344 KB Output is correct
5 Correct 1443 ms 160036 KB Output is correct
6 Correct 25 ms 64980 KB Output is correct
7 Correct 1384 ms 122352 KB Output is correct
8 Correct 1363 ms 171952 KB Output is correct
9 Correct 1328 ms 122136 KB Output is correct
10 Correct 1396 ms 159112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 65016 KB Output is correct
2 Correct 31 ms 65040 KB Output is correct
3 Correct 62 ms 65016 KB Output is correct
4 Correct 25 ms 65012 KB Output is correct
5 Correct 42 ms 65044 KB Output is correct
6 Correct 27 ms 64980 KB Output is correct
7 Correct 1458 ms 112076 KB Output is correct
8 Correct 1420 ms 126924 KB Output is correct
9 Correct 1353 ms 122040 KB Output is correct
10 Correct 1435 ms 159344 KB Output is correct
11 Correct 1443 ms 160036 KB Output is correct
12 Correct 25 ms 64980 KB Output is correct
13 Correct 1384 ms 122352 KB Output is correct
14 Correct 1363 ms 171952 KB Output is correct
15 Correct 1328 ms 122136 KB Output is correct
16 Correct 1396 ms 159112 KB Output is correct
17 Correct 1318 ms 125020 KB Output is correct
18 Correct 1287 ms 123928 KB Output is correct
19 Correct 1321 ms 157000 KB Output is correct
20 Correct 1252 ms 123072 KB Output is correct
21 Correct 1345 ms 150012 KB Output is correct
22 Correct 1313 ms 150500 KB Output is correct
23 Correct 1224 ms 124140 KB Output is correct
24 Correct 1231 ms 173296 KB Output is correct
25 Correct 1249 ms 119628 KB Output is correct
26 Correct 1281 ms 130436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 65016 KB Output is correct
2 Correct 31 ms 65040 KB Output is correct
3 Correct 62 ms 65016 KB Output is correct
4 Correct 25 ms 65012 KB Output is correct
5 Correct 42 ms 65044 KB Output is correct
6 Correct 27 ms 64980 KB Output is correct
7 Correct 1458 ms 112076 KB Output is correct
8 Correct 1420 ms 126924 KB Output is correct
9 Correct 1353 ms 122040 KB Output is correct
10 Correct 1435 ms 159344 KB Output is correct
11 Correct 1443 ms 160036 KB Output is correct
12 Correct 25 ms 64980 KB Output is correct
13 Correct 1384 ms 122352 KB Output is correct
14 Correct 1363 ms 171952 KB Output is correct
15 Correct 1328 ms 122136 KB Output is correct
16 Correct 1396 ms 159112 KB Output is correct
17 Correct 1318 ms 125020 KB Output is correct
18 Correct 1287 ms 123928 KB Output is correct
19 Correct 1321 ms 157000 KB Output is correct
20 Correct 1252 ms 123072 KB Output is correct
21 Correct 1345 ms 150012 KB Output is correct
22 Correct 1313 ms 150500 KB Output is correct
23 Correct 1224 ms 124140 KB Output is correct
24 Correct 1231 ms 173296 KB Output is correct
25 Correct 1249 ms 119628 KB Output is correct
26 Correct 1281 ms 130436 KB Output is correct
27 Correct 1508 ms 133688 KB Output is correct
28 Correct 1590 ms 132940 KB Output is correct
29 Correct 1545 ms 141340 KB Output is correct
30 Correct 1465 ms 128224 KB Output is correct
31 Correct 1524 ms 143912 KB Output is correct
32 Correct 1589 ms 144240 KB Output is correct
33 Correct 1348 ms 154036 KB Output is correct
34 Correct 1561 ms 124844 KB Output is correct
35 Correct 1583 ms 144084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 65016 KB Output is correct
2 Correct 31 ms 65040 KB Output is correct
3 Correct 62 ms 65016 KB Output is correct
4 Correct 25 ms 65012 KB Output is correct
5 Correct 42 ms 65044 KB Output is correct
6 Correct 27 ms 64980 KB Output is correct
7 Correct 1458 ms 112076 KB Output is correct
8 Correct 1420 ms 126924 KB Output is correct
9 Correct 1353 ms 122040 KB Output is correct
10 Correct 1435 ms 159344 KB Output is correct
11 Correct 1443 ms 160036 KB Output is correct
12 Correct 25 ms 64980 KB Output is correct
13 Correct 1384 ms 122352 KB Output is correct
14 Correct 1363 ms 171952 KB Output is correct
15 Correct 1328 ms 122136 KB Output is correct
16 Correct 1396 ms 159112 KB Output is correct
17 Correct 1318 ms 125020 KB Output is correct
18 Correct 1287 ms 123928 KB Output is correct
19 Correct 1321 ms 157000 KB Output is correct
20 Correct 1252 ms 123072 KB Output is correct
21 Correct 1345 ms 150012 KB Output is correct
22 Correct 1313 ms 150500 KB Output is correct
23 Correct 1224 ms 124140 KB Output is correct
24 Correct 1231 ms 173296 KB Output is correct
25 Correct 1249 ms 119628 KB Output is correct
26 Correct 1281 ms 130436 KB Output is correct
27 Correct 1508 ms 133688 KB Output is correct
28 Correct 1590 ms 132940 KB Output is correct
29 Correct 1545 ms 141340 KB Output is correct
30 Correct 1465 ms 128224 KB Output is correct
31 Correct 1524 ms 143912 KB Output is correct
32 Correct 1589 ms 144240 KB Output is correct
33 Correct 1348 ms 154036 KB Output is correct
34 Correct 1561 ms 124844 KB Output is correct
35 Correct 1583 ms 144084 KB Output is correct
36 Correct 2466 ms 130136 KB Output is correct
37 Correct 2505 ms 162904 KB Output is correct
38 Correct 2567 ms 166892 KB Output is correct
39 Correct 2577 ms 195508 KB Output is correct
40 Correct 2638 ms 189196 KB Output is correct
41 Correct 1418 ms 195480 KB Output is correct
42 Correct 2558 ms 154564 KB Output is correct
43 Correct 2544 ms 154920 KB Output is correct