답안 #421979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421979 2021-06-09T14:23:54 Z lyc Escape Route (JOI21_escape_route) C++17
0 / 100
9000 ms 111956 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];
vector<ll> zdist[mxN];

vector<ll> dijkstra(int s, int t) {
    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();
        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 dist;
}

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){
        zdist[i] = dijkstra(i,0);
    }

    vector<ll> ans(Q);
    FOR(i,0,Q-1){
        vector<ll> mdist = dijkstra(U[i],T[i]), tmp;
        //FOR(j,0,N-1){ cout << mdist[j] << ' '; } cout << endl;
        ans[i] = -T[i];

        if (mdist[V[i]] < S+1) {
            ans[i] += mdist[V[i]];
            continue;
        }

        ll t = S;
        while (true) {
            tmp.assign(N,S+1);
            FOR(j,0,N-1) if (mdist[j] < S+1) {
                FOR(k,0,N-1){
                    tmp[k] = min(tmp[k], zdist[j][k]);
                }
            }
            swap(mdist,tmp);
            if (mdist[V[i]] < S+1) {
                ans[i] += t + mdist[V[i]];
                break;
            } else t += S;
        }
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 64980 KB Output is correct
2 Correct 32 ms 64952 KB Output is correct
3 Incorrect 44 ms 64952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9084 ms 111956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 64980 KB Output is correct
2 Correct 32 ms 64952 KB Output is correct
3 Incorrect 44 ms 64952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 64980 KB Output is correct
2 Correct 32 ms 64952 KB Output is correct
3 Incorrect 44 ms 64952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 64980 KB Output is correct
2 Correct 32 ms 64952 KB Output is correct
3 Incorrect 44 ms 64952 KB Output isn't correct
4 Halted 0 ms 0 KB -