답안 #422021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422021 2021-06-09T14:58:58 Z lyc Escape Route (JOI21_escape_route) C++17
5 / 100
9000 ms 111948 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, ll t) {
    vector<ll> dist(N,S+1);

    using data = pair<ll,int>;
    priority_queue<data,vector<data>,greater<data>> 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;
        }
    }

    //TRACE(SZ(ans));
    //for (auto& x  : ans) { cout << x << ' '; } cout << endl;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 64972 KB Output is correct
2 Correct 36 ms 65016 KB Output is correct
3 Correct 42 ms 64976 KB Output is correct
4 Correct 30 ms 64932 KB Output is correct
5 Correct 31 ms 64936 KB Output is correct
6 Correct 33 ms 64972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9089 ms 111948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 64972 KB Output is correct
2 Correct 36 ms 65016 KB Output is correct
3 Correct 42 ms 64976 KB Output is correct
4 Correct 30 ms 64932 KB Output is correct
5 Correct 31 ms 64936 KB Output is correct
6 Correct 33 ms 64972 KB Output is correct
7 Execution timed out 9089 ms 111948 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 64972 KB Output is correct
2 Correct 36 ms 65016 KB Output is correct
3 Correct 42 ms 64976 KB Output is correct
4 Correct 30 ms 64932 KB Output is correct
5 Correct 31 ms 64936 KB Output is correct
6 Correct 33 ms 64972 KB Output is correct
7 Execution timed out 9089 ms 111948 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 64972 KB Output is correct
2 Correct 36 ms 65016 KB Output is correct
3 Correct 42 ms 64976 KB Output is correct
4 Correct 30 ms 64932 KB Output is correct
5 Correct 31 ms 64936 KB Output is correct
6 Correct 33 ms 64972 KB Output is correct
7 Execution timed out 9089 ms 111948 KB Time limit exceeded
8 Halted 0 ms 0 KB -