結果

問題 No.1 道のショートカット
ユーザー kappybarkappybar
提出日時 2020-06-21 18:01:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,670 bytes
コンパイル時間 2,688 ms
コンパイル使用メモリ 177,388 KB
実行使用メモリ 13,400 KB
最終ジャッジ日時 2023-09-27 22:30:46
合計ジャッジ時間 3,624 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 10 ms
7,820 KB
testcase_09 AC 9 ms
7,096 KB
testcase_10 AC 13 ms
10,032 KB
testcase_11 AC 15 ms
11,920 KB
testcase_12 AC 14 ms
9,172 KB
testcase_13 AC 13 ms
9,208 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 5 ms
5,008 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 3 ms
4,536 KB
testcase_19 AC 4 ms
4,620 KB
testcase_20 AC 6 ms
5,364 KB
testcase_21 AC 4 ms
4,576 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 23 ms
13,400 KB
testcase_24 AC 18 ms
10,852 KB
testcase_25 AC 7 ms
5,980 KB
testcase_26 AC 5 ms
4,912 KB
testcase_27 AC 17 ms
10,932 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 15 ms
12,532 KB
testcase_30 AC 6 ms
6,192 KB
testcase_31 AC 8 ms
9,412 KB
testcase_32 AC 8 ms
6,684 KB
testcase_33 AC 7 ms
6,532 KB
testcase_34 AC 11 ms
9,624 KB
testcase_35 AC 7 ms
8,580 KB
testcase_36 AC 11 ms
9,172 KB
testcase_37 AC 10 ms
9,992 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 7 ms
6,476 KB
testcase_41 AC 4 ms
4,624 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int n = 55 * 305;
int m;
vector<vector<pll>> graph(n,vector<pll>());

vector<ll>  Dijkstra(int start){
    vector<bool> seen(55 * 305,false);
    vector<ll> shortest(55 * 305,LINF);
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push(pll(0,start));

    while(!pq.empty()){
        ll dist = pq.top().first;
        int node = pq.top().second;
        pq.pop();
        if(seen[node]) continue;

        shortest[node] = dist;
        seen[node] = true;

        for(pll next:graph[node]){
            int next_node = next.second;
            ll next_cost = next.first;
            if(seen[next_node]) continue;
            pq.push(pll(next_cost + dist,next_node));
        }
    }

    return shortest;
}

int main(){
    cin >> n;
    int c;
    cin >> c;
    cin >> m;
    vector<int> a(m),b(m),y(m),t(m);
    rep(i,m) cin >> a[i],--a[i];
    rep(i,m) cin >> b[i],--b[i];
    rep(i,m) cin >> y[i];
    rep(i,m) cin >> t[i];
    rep(i,m){
        for(int j=y[i];j<=300;j++){
            graph[a[i]*301+j].push_back(pll(t[i],b[i]*301+j-y[i]));
            //graph[b[i]*301+j].push_back(pll(t[i],a[i]*301+j-y[i]));
        }
    }

    vector<ll> answer = Dijkstra(0 + c);
    ll ans = LINF;
    rep(i,c+1){
        ans = min(ans,answer[(n-1)*301+i]);
    }
    if(ans==LINF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
0