結果

問題 No.1 道のショートカット
ユーザー IrmystpIrmystp
提出日時 2014-11-26 20:38:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 146,052 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 11:46:53
合計ジャッジ時間 2,628 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
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(50);
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