답안 #521992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521992 2022-02-03T14:51:33 Z eecs Escape Route (JOI21_escape_route) C++17
100 / 100
4536 ms 144592 KB
#include "escape_route.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll INF = 1e18;

void chk(ll &x, ll y) {
    if (x > y) x = y;
}

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<vector<ll>> W(n, vector<ll>(n, -1)), lim = W;
    for (int i = 0; i < m; i++) {
        W[A[i]][B[i]] = W[B[i]][A[i]] = L[i];
        lim[A[i]][B[i]] = lim[B[i]][A[i]] = C[i] - L[i];
    }
    auto dijkstra = [&](vector<ll> &d) {
        vector<bool> vis(n);
        while (1) {
            int u = -1;
            for (int i = 0; i < n; i++) {
                if (!vis[i] && d[i] < INF && (!~u || d[u] > d[i])) u = i;
            }
            if (!~u) break;
            vis[u] = 1;
            for (int i = 0; i < n; i++) if (~W[u][i]) {
                if (d[u] % S <= lim[u][i]) chk(d[i], d[u] + W[u][i]);
                else chk(d[i], (d[u] + S - 1) / S * S + W[u][i]);
            }
        }
    };
    vector<vector<ll>> dv(n, vector<ll>(n, INF));
    vector<vector<vector<ll>>> de(n, dv);
    for (int i = 0; i < n; i++) {
        dv[i][i] = 0, dijkstra(dv[i]);
        for (int j = 0; j < n; j++) if (~W[i][j]) {
            de[i][j][i] = lim[i][j], dijkstra(de[i][j]);
            for (int k = 0; k < n; k++) {
                de[i][j][k] = de[i][j][k] < S ? de[i][j][k] - lim[i][j] : INF;
            }
        }
    }
    vector<vector<int>> G(n), Q(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (~W[i][j]) G[i].push_back(j);
        }
        sort(G[i].begin(), G[i].end(), [&](int x, int y) { return lim[i][x] > lim[i][y]; });
    }
    vector<ll> ans(q, INF);
    for (int i = 0; i < q; i++) {
        Q[U[i]].push_back(i);
    }
    for (int s = 0; s < n; s++) {
        sort(Q[s].begin(), Q[s].end(), [&](int x, int y) { return T[x] < T[y]; });
        vector<int> cur(n);
        vector<ll> dist(n, INF), tim(n, -1);
        dist[s] = 0, tim[s] = lim[s][G[s][0]];
        while (1) {
            int u = max_element(tim.begin(), tim.end()) - tim.begin();
            for (; !Q[s].empty() && T[Q[s].back()] > tim[u]; Q[s].pop_back()) {
                int k = Q[s].back();
                for (int i = 0; i < n; i++) {
                    chk(ans[k], dist[i] + (i != V[k] ? (S - (dist[i] + T[k]) % S) % S : 0) + dv[i][V[k]]);
                }
            }
            if (!~tim[u]) break;
            int v = G[u][cur[u]++];
            tim[u] = cur[u] < G[u].size() ? lim[u][G[u][cur[u]]] - dist[u] : -1;
            for (int i = 0; i < n; i++) if (dist[i] > dist[u] + de[u][v][i]) {
                dist[i] = dist[u] + de[u][v][i];
                if (cur[i] < G[i].size()) tim[i] = lim[i][G[i][cur[i]]] - dist[i];
            }
        }
    }
    return ans;
}

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:72:29: 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]
   72 |             tim[u] = cur[u] < G[u].size() ? lim[u][G[u][cur[u]]] - dist[u] : -1;
escape_route.cpp:75:28: 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]
   75 |                 if (cur[i] < G[i].size()) tim[i] = lim[i][G[i][cur[i]]] - dist[i];
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 65 ms 65100 KB Output is correct
4 Correct 26 ms 64972 KB Output is correct
5 Correct 54 ms 64988 KB Output is correct
6 Correct 28 ms 64984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2116 ms 116280 KB Output is correct
2 Correct 2192 ms 132352 KB Output is correct
3 Correct 2172 ms 123908 KB Output is correct
4 Correct 2212 ms 132080 KB Output is correct
5 Correct 2215 ms 131884 KB Output is correct
6 Correct 24 ms 64972 KB Output is correct
7 Correct 2263 ms 123384 KB Output is correct
8 Correct 2292 ms 144592 KB Output is correct
9 Correct 2176 ms 123332 KB Output is correct
10 Correct 2242 ms 131916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 65 ms 65100 KB Output is correct
4 Correct 26 ms 64972 KB Output is correct
5 Correct 54 ms 64988 KB Output is correct
6 Correct 28 ms 64984 KB Output is correct
7 Correct 2116 ms 116280 KB Output is correct
8 Correct 2192 ms 132352 KB Output is correct
9 Correct 2172 ms 123908 KB Output is correct
10 Correct 2212 ms 132080 KB Output is correct
11 Correct 2215 ms 131884 KB Output is correct
12 Correct 24 ms 64972 KB Output is correct
13 Correct 2263 ms 123384 KB Output is correct
14 Correct 2292 ms 144592 KB Output is correct
15 Correct 2176 ms 123332 KB Output is correct
16 Correct 2242 ms 131916 KB Output is correct
17 Correct 2061 ms 122984 KB Output is correct
18 Correct 2015 ms 122536 KB Output is correct
19 Correct 2087 ms 131976 KB Output is correct
20 Correct 2058 ms 122492 KB Output is correct
21 Correct 2101 ms 132900 KB Output is correct
22 Correct 2128 ms 132640 KB Output is correct
23 Correct 2121 ms 122588 KB Output is correct
24 Correct 2150 ms 144376 KB Output is correct
25 Correct 2092 ms 123052 KB Output is correct
26 Correct 2120 ms 131940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 65 ms 65100 KB Output is correct
4 Correct 26 ms 64972 KB Output is correct
5 Correct 54 ms 64988 KB Output is correct
6 Correct 28 ms 64984 KB Output is correct
7 Correct 2116 ms 116280 KB Output is correct
8 Correct 2192 ms 132352 KB Output is correct
9 Correct 2172 ms 123908 KB Output is correct
10 Correct 2212 ms 132080 KB Output is correct
11 Correct 2215 ms 131884 KB Output is correct
12 Correct 24 ms 64972 KB Output is correct
13 Correct 2263 ms 123384 KB Output is correct
14 Correct 2292 ms 144592 KB Output is correct
15 Correct 2176 ms 123332 KB Output is correct
16 Correct 2242 ms 131916 KB Output is correct
17 Correct 2061 ms 122984 KB Output is correct
18 Correct 2015 ms 122536 KB Output is correct
19 Correct 2087 ms 131976 KB Output is correct
20 Correct 2058 ms 122492 KB Output is correct
21 Correct 2101 ms 132900 KB Output is correct
22 Correct 2128 ms 132640 KB Output is correct
23 Correct 2121 ms 122588 KB Output is correct
24 Correct 2150 ms 144376 KB Output is correct
25 Correct 2092 ms 123052 KB Output is correct
26 Correct 2120 ms 131940 KB Output is correct
27 Correct 2753 ms 122368 KB Output is correct
28 Correct 2713 ms 123544 KB Output is correct
29 Correct 2800 ms 133980 KB Output is correct
30 Correct 2765 ms 125480 KB Output is correct
31 Correct 2795 ms 138204 KB Output is correct
32 Correct 2815 ms 134760 KB Output is correct
33 Correct 2758 ms 142876 KB Output is correct
34 Correct 2784 ms 120028 KB Output is correct
35 Correct 2921 ms 132752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 65 ms 65100 KB Output is correct
4 Correct 26 ms 64972 KB Output is correct
5 Correct 54 ms 64988 KB Output is correct
6 Correct 28 ms 64984 KB Output is correct
7 Correct 2116 ms 116280 KB Output is correct
8 Correct 2192 ms 132352 KB Output is correct
9 Correct 2172 ms 123908 KB Output is correct
10 Correct 2212 ms 132080 KB Output is correct
11 Correct 2215 ms 131884 KB Output is correct
12 Correct 24 ms 64972 KB Output is correct
13 Correct 2263 ms 123384 KB Output is correct
14 Correct 2292 ms 144592 KB Output is correct
15 Correct 2176 ms 123332 KB Output is correct
16 Correct 2242 ms 131916 KB Output is correct
17 Correct 2061 ms 122984 KB Output is correct
18 Correct 2015 ms 122536 KB Output is correct
19 Correct 2087 ms 131976 KB Output is correct
20 Correct 2058 ms 122492 KB Output is correct
21 Correct 2101 ms 132900 KB Output is correct
22 Correct 2128 ms 132640 KB Output is correct
23 Correct 2121 ms 122588 KB Output is correct
24 Correct 2150 ms 144376 KB Output is correct
25 Correct 2092 ms 123052 KB Output is correct
26 Correct 2120 ms 131940 KB Output is correct
27 Correct 2753 ms 122368 KB Output is correct
28 Correct 2713 ms 123544 KB Output is correct
29 Correct 2800 ms 133980 KB Output is correct
30 Correct 2765 ms 125480 KB Output is correct
31 Correct 2795 ms 138204 KB Output is correct
32 Correct 2815 ms 134760 KB Output is correct
33 Correct 2758 ms 142876 KB Output is correct
34 Correct 2784 ms 120028 KB Output is correct
35 Correct 2921 ms 132752 KB Output is correct
36 Correct 4467 ms 121476 KB Output is correct
37 Correct 4456 ms 115244 KB Output is correct
38 Correct 4499 ms 119772 KB Output is correct
39 Correct 4536 ms 131316 KB Output is correct
40 Correct 4510 ms 131832 KB Output is correct
41 Correct 3653 ms 143976 KB Output is correct
42 Correct 4525 ms 113916 KB Output is correct
43 Correct 4469 ms 113224 KB Output is correct