Submission #422054

# Submission time Handle Problem Language Result Execution time Memory
422054 2021-06-09T16:28:54 Z lyc Escape Route (JOI21_escape_route) C++17
5 / 100
9000 ms 113036 KB
#include "escape_route.h"

#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)

const int mxN = 90;

typedef long long ll;
struct Edge { int v; ll l, c; };
int N;
ll S;
vector<Edge> al[mxN];

pair<bitset<mxN>, vector<ll>> dijkstra(int s, ll t) {
    bitset<mxN> vis; vis.reset();
    vector<ll> dist(N,S+1);

    priority_queue<pair<ll,int>> pq;
    pq.push(make_pair(-t,s)); dist[s] = t;

    while (!pq.empty()) {
        int u = pq.top().second;
        ll w = -pq.top().first;
        pq.pop();
        vis[u] = 1;
        if (w > dist[u]) continue;
        for (auto& e : al[u]) {
            if (w+e.l <= e.c && w+e.l <= dist[e.v]) {
                dist[e.v] = w+e.l;
                pq.push(make_pair(-dist[e.v],e.v));
            }
        }
    }

    return make_pair(vis,dist);
}

map<ll, bitset<mxN>> bounds[mxN];
bitset<mxN> ok[mxN][mxN];
vector<ll> zdist[mxN];

void dnc(ll s, ll e, int i, bitset<mxN> mn, bitset<mxN> mx) {
    bounds[i][s] = mn;
    FOR(j,s+1,e-1){
        auto cur = dijkstra(i,j).first;
        if (cur != mn) bounds[i][j] = mn = cur;
    }

    //if (s+1 == e) {
    //    bounds[i][s] = mn;
    //    return;
    //}

    //ll m = (s+e)/2;
    //auto cur = dijkstra(i,m).first;

    //if (mn != cur) dnc(s,m,i,mn,cur);
    //if (cur != mx) dnc(m,e,i,cur,mx);
}

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;
    S = _S;


    FOR(i,0,M-1){
        al[A[i]].push_back({B[i],L[i],C[i]});
        al[B[i]].push_back({A[i],L[i],C[i]});
    }

    FOR(i,0,N-1){
        auto mn = dijkstra(i,0);
        auto mx = dijkstra(i,S+1);
        //dnc(0,S+1,i,mn.first,mx.first);
        //for (auto& x : bounds[i]) {
        //    TRACE(i _ x.first _ x.second.count());
        //}

        ok[i][0] = mn.first;
        zdist[i] = mn.second;
    }

    FOR(k,1,6){
        FOR(i,0,N-1){
            ok[i][k].reset();
            FOR(j,0,N-1) if (ok[i][k-1][j]) {
                ok[i][k] |= ok[j][k-1];
            }
        }
    }

    //FOR(i,0,N-1){
    //    FOR(k,0,6){
    //        TRACE(i _ ok[i][k]);
    //    }
    //    cout <<endl;
    //}

    vector<ll> ans(Q);
    FOR(i,0,Q-1){
        //auto st = (--bounds[U[i]].lower_bound(T[i]+1))->second;
        auto d = dijkstra(U[i],T[i]);
        auto st = d.first;

        if (st[V[i]]) {
            ans[i] = d.second[V[i]] - T[i];
        } else {
            ans[i] = S;
            RFOR(k,6,0){
                bitset<mxN> tmp; tmp.reset();
                FOR(j,0,N-1) if (st[j]) {
                    tmp |= ok[j][k];
                }
                if (!tmp[V[i]]) {
                    st |= tmp;
                    ans[i] += (1<<k) * S;
                }
            }

            ll mn = S+1;
            FOR(j,0,N-1) if (st[j]) {
                mn = min(mn, zdist[j][V[i]]);
            }
            //TRACE( i _ ans[i] _ mn );
            ans[i] += mn;

            ans[i] -= T[i];
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 48 ms 65088 KB Output is correct
4 Correct 28 ms 64952 KB Output is correct
5 Correct 32 ms 64972 KB Output is correct
6 Correct 29 ms 64992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 9009 ms 113036 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 48 ms 65088 KB Output is correct
4 Correct 28 ms 64952 KB Output is correct
5 Correct 32 ms 64972 KB Output is correct
6 Correct 29 ms 64992 KB Output is correct
7 Execution timed out 9009 ms 113036 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 48 ms 65088 KB Output is correct
4 Correct 28 ms 64952 KB Output is correct
5 Correct 32 ms 64972 KB Output is correct
6 Correct 29 ms 64992 KB Output is correct
7 Execution timed out 9009 ms 113036 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 64972 KB Output is correct
2 Correct 31 ms 64972 KB Output is correct
3 Correct 48 ms 65088 KB Output is correct
4 Correct 28 ms 64952 KB Output is correct
5 Correct 32 ms 64972 KB Output is correct
6 Correct 29 ms 64992 KB Output is correct
7 Execution timed out 9009 ms 113036 KB Time limit exceeded
8 Halted 0 ms 0 KB -