답안 #617747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617747 2022-08-01T13:13:32 Z qwerasdfzxcl Escape Route (JOI21_escape_route) C++17
70 / 100
9000 ms 314328 KB
#include "escape_route.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF = 4e18;
struct Edge{
    int v;
    ll l, c;
    Edge(){}
    Edge(int _v, ll _l, ll _c): v(_v), l(_l), c(_c) {}
};
vector<Edge> adj[101];
int n, m, q;
ll MOD, dist0[101][101], ran[101][4040], dist[101][4040][101], par[101], sz[101];
bool visited[101];

vector<ll> ans;

ll dijkstra(int s, ll t, ll dist[], bool is0){
    fill(dist+1, dist+n+1, INF);
    fill(visited+1, visited+n+1, 0);
    fill(par+1, par+n+1, INF);

    dist[s] = t;
    ll ret = INF;

    for (int i=1;i<=n;i++){
        ll mn = INF, v = -1;
        for (int j=1;j<=n;j++) if (!visited[j] && mn > dist[j]) mn = dist[j], v = j;
        if (v==-1) break;

        visited[v] = 1;
        ret = min(ret, par[v]);
        //printf(" %d %lld\n", v, mn);

        for (auto &[nxt, l, c]:adj[v]) if (!visited[nxt]){
            ll nt = mn + l;
            if (mn%MOD > c-l){
                if (!is0) continue;
                nt = (mn/MOD*MOD + MOD) + l;
            }

            if (nt < dist[nxt]){
                dist[nxt] = nt;
                if (!is0) par[nxt] = c-l-mn+1;
            }
        }
    }

    return ret;
}

struct FUCK{
    int u, v, i;
    ll t;
    FUCK(){}
    FUCK(int _u, int _v, ll _t, int _i): u(_u), v(_v), i(_i), t(_t) {}
    bool operator<(const FUCK &FUUUUUCK) const{
        return tie(u, t) < tie(FUUUUUCK.u, FUUUUUCK.t);
    }
}fuck[3003000];

int fuuck[101];

std::vector<long long> calculate_necessary_time(
    int N, int M, long long S, int Q, std::vector<int> A, std::vector<int> B,
    std::vector<long long> L, std::vector<long long> C, std::vector<int> U,
    std::vector<int> V, std::vector<long long> T) {

    n = N, m = M, MOD = S, q = Q;
    for (int i=0;i<m;i++){
        ++A[i], ++B[i];

        adj[A[i]].emplace_back(B[i], L[i], C[i]);
        adj[B[i]].emplace_back(A[i], L[i], C[i]);
    }

    for (int i=1;i<=n;i++) dijkstra(i, 0, dist0[i], 1);
    for (int i=1;i<=n;i++){
        int pt = 0;
        ll curt = 0;
        while(true){
            assert(pt<=m+2);
            ran[i][pt] = curt;
            ll tmp = dijkstra(i, curt, dist[i][pt], 0);

            ++pt;
            curt += tmp;
            if (curt >= MOD) break;

        }

        /*if (i==1){
            for (int j=0;j<pt;j++) printf(" %lld", ran[i][j]);
            printf("\n");
        }*/

        ran[i][pt] = MOD;
        sz[i] = pt+1;
    }

    //printf("  %lld\n", dist[1][0][4]);

    for (int i=0;i<q;i++) fuck[i] = FUCK(U[i]+1, V[i]+1, T[i], i);
    sort(fuck, fuck+q);
    ans.resize(q);

    for (int i=0;i<q;i++){
        int u = fuck[i].u;
        int v = fuck[i].v;
        int ii = fuck[i].i;
        ll t = fuck[i].t;

        while(fuuck[u]<sz[u] && ran[u][fuuck[u]] <=  t) fuuck[u]++;
        int pt = fuuck[u] - 1;
        //printf(" %d %d %lld -> %d\n", U[i], V[i], T[i], pt);
        ll ret = dist[u][pt][v] - ran[u][pt];
        for (int j=1;j<=n;j++) if (dist[u][pt][j]<INF){
            ret = min(ret, MOD - t + dist0[j][v]);
        }
        ans[ii] = ret;
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 64972 KB Output is correct
2 Correct 31 ms 65060 KB Output is correct
3 Correct 79 ms 65088 KB Output is correct
4 Correct 27 ms 65024 KB Output is correct
5 Correct 34 ms 65112 KB Output is correct
6 Correct 28 ms 65012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1092 ms 220188 KB Output is correct
2 Correct 1238 ms 239776 KB Output is correct
3 Correct 840 ms 217248 KB Output is correct
4 Correct 1163 ms 247992 KB Output is correct
5 Correct 1139 ms 253912 KB Output is correct
6 Correct 27 ms 64980 KB Output is correct
7 Correct 951 ms 216080 KB Output is correct
8 Correct 920 ms 249324 KB Output is correct
9 Correct 1000 ms 216764 KB Output is correct
10 Correct 1163 ms 254580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 64972 KB Output is correct
2 Correct 31 ms 65060 KB Output is correct
3 Correct 79 ms 65088 KB Output is correct
4 Correct 27 ms 65024 KB Output is correct
5 Correct 34 ms 65112 KB Output is correct
6 Correct 28 ms 65012 KB Output is correct
7 Correct 1092 ms 220188 KB Output is correct
8 Correct 1238 ms 239776 KB Output is correct
9 Correct 840 ms 217248 KB Output is correct
10 Correct 1163 ms 247992 KB Output is correct
11 Correct 1139 ms 253912 KB Output is correct
12 Correct 27 ms 64980 KB Output is correct
13 Correct 951 ms 216080 KB Output is correct
14 Correct 920 ms 249324 KB Output is correct
15 Correct 1000 ms 216764 KB Output is correct
16 Correct 1163 ms 254580 KB Output is correct
17 Correct 1100 ms 221564 KB Output is correct
18 Correct 1141 ms 225216 KB Output is correct
19 Correct 1193 ms 248560 KB Output is correct
20 Correct 884 ms 227780 KB Output is correct
21 Correct 1223 ms 248644 KB Output is correct
22 Correct 1182 ms 248440 KB Output is correct
23 Correct 871 ms 209580 KB Output is correct
24 Correct 995 ms 237900 KB Output is correct
25 Correct 1038 ms 209888 KB Output is correct
26 Correct 1215 ms 248868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 64972 KB Output is correct
2 Correct 31 ms 65060 KB Output is correct
3 Correct 79 ms 65088 KB Output is correct
4 Correct 27 ms 65024 KB Output is correct
5 Correct 34 ms 65112 KB Output is correct
6 Correct 28 ms 65012 KB Output is correct
7 Correct 1092 ms 220188 KB Output is correct
8 Correct 1238 ms 239776 KB Output is correct
9 Correct 840 ms 217248 KB Output is correct
10 Correct 1163 ms 247992 KB Output is correct
11 Correct 1139 ms 253912 KB Output is correct
12 Correct 27 ms 64980 KB Output is correct
13 Correct 951 ms 216080 KB Output is correct
14 Correct 920 ms 249324 KB Output is correct
15 Correct 1000 ms 216764 KB Output is correct
16 Correct 1163 ms 254580 KB Output is correct
17 Correct 1100 ms 221564 KB Output is correct
18 Correct 1141 ms 225216 KB Output is correct
19 Correct 1193 ms 248560 KB Output is correct
20 Correct 884 ms 227780 KB Output is correct
21 Correct 1223 ms 248644 KB Output is correct
22 Correct 1182 ms 248440 KB Output is correct
23 Correct 871 ms 209580 KB Output is correct
24 Correct 995 ms 237900 KB Output is correct
25 Correct 1038 ms 209888 KB Output is correct
26 Correct 1215 ms 248868 KB Output is correct
27 Correct 2629 ms 259944 KB Output is correct
28 Correct 2921 ms 276632 KB Output is correct
29 Correct 3295 ms 302528 KB Output is correct
30 Correct 1132 ms 217424 KB Output is correct
31 Correct 3255 ms 301160 KB Output is correct
32 Correct 3285 ms 296844 KB Output is correct
33 Correct 1008 ms 233664 KB Output is correct
34 Correct 2435 ms 247160 KB Output is correct
35 Correct 3323 ms 314328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 64972 KB Output is correct
2 Correct 31 ms 65060 KB Output is correct
3 Correct 79 ms 65088 KB Output is correct
4 Correct 27 ms 65024 KB Output is correct
5 Correct 34 ms 65112 KB Output is correct
6 Correct 28 ms 65012 KB Output is correct
7 Correct 1092 ms 220188 KB Output is correct
8 Correct 1238 ms 239776 KB Output is correct
9 Correct 840 ms 217248 KB Output is correct
10 Correct 1163 ms 247992 KB Output is correct
11 Correct 1139 ms 253912 KB Output is correct
12 Correct 27 ms 64980 KB Output is correct
13 Correct 951 ms 216080 KB Output is correct
14 Correct 920 ms 249324 KB Output is correct
15 Correct 1000 ms 216764 KB Output is correct
16 Correct 1163 ms 254580 KB Output is correct
17 Correct 1100 ms 221564 KB Output is correct
18 Correct 1141 ms 225216 KB Output is correct
19 Correct 1193 ms 248560 KB Output is correct
20 Correct 884 ms 227780 KB Output is correct
21 Correct 1223 ms 248644 KB Output is correct
22 Correct 1182 ms 248440 KB Output is correct
23 Correct 871 ms 209580 KB Output is correct
24 Correct 995 ms 237900 KB Output is correct
25 Correct 1038 ms 209888 KB Output is correct
26 Correct 1215 ms 248868 KB Output is correct
27 Correct 2629 ms 259944 KB Output is correct
28 Correct 2921 ms 276632 KB Output is correct
29 Correct 3295 ms 302528 KB Output is correct
30 Correct 1132 ms 217424 KB Output is correct
31 Correct 3255 ms 301160 KB Output is correct
32 Correct 3285 ms 296844 KB Output is correct
33 Correct 1008 ms 233664 KB Output is correct
34 Correct 2435 ms 247160 KB Output is correct
35 Correct 3323 ms 314328 KB Output is correct
36 Execution timed out 9031 ms 181440 KB Time limit exceeded
37 Halted 0 ms 0 KB -