結果

問題 No.1 道のショートカット
ユーザー IrmystpIrmystp
提出日時 2014-11-26 20:39:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,402 bytes
コンパイル時間 1,206 ms
コンパイル使用メモリ 145,840 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-27 21:36:49
合計ジャッジ時間 2,474 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,504 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 7 ms
4,380 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 6 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int INF = 1<<29;

struct edge{
    int from;
    int to;
    int dist;
    int cost;
    edge(){} ~edge(){}
    edge(int a, int b, int c): to(a), dist(b), cost(c) {}
    bool operator <(const edge& r) const {
        return dist > r.dist;
    }
};

int N, C, V;
vector<edge> G(1500);
int d[51][301];

int main(){
    scanf("%d%d%d", &N, &C, &V);
    for(int x = 0; x < V; x++){
        scanf("%d", &G[x].from);
    }
    for(int x = 0; x < V; x++){
        scanf("%d", &G[x].to);
    }
    for(int x = 0; x < V; x++){
        scanf("%d", &G[x].cost);
    }
    for(int x = 0; x < V; x++){
        scanf("%d", &G[x].dist);
    }
    for(int x = 0; x <= N; x++){
        fill(d[x], d[x]+C+1, INF);
    }
    d[1][C] = 0;
    for(int x = 0; x < N; x++){
        bool updated = false;
        for(auto& e : G){
            for(int y = e.cost; y <= C; y++){
                if(d[e.from][y] + e.dist < d[e.to][y - e.cost]){
                    updated = true;
                    d[e.to][y - e.cost] = d[e.from][y] + e.dist;
                }
            }
        }
        if(!updated) break;
    }
    int res = INF;
    for(int x = 0; x <= C; x++){
        res = min(res, d[N][x]);
    }
    if(res < INF){
        printf("%d\n", res);
    }else{
        puts("-1");
    }
    return 0;
}
0