結果

問題 No.1 道のショートカット
ユーザー dsytk7dsytk7
提出日時 2017-07-06 17:32:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 837 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 144,956 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:08:57
合計ジャッジ時間 3,067 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;

const int V = 50;
const int C = 301;
const int E = 1500;
const int inf = 1e8;

ll dp[V][C];
ll a[E], b[E], t[E], cost[E];

int main() {
    ll v, m, e;
    cin >> v >> m >> e;
    v--;

    rep(i, e) cin >> a[i], a[i]--;
    rep(i, e) cin >> b[i], b[i]--;
    rep(i, e) cin >> cost[i];
    rep(i, e) cin >> t[i];

    rep(i, V) rep(j, C) dp[i][j] = inf;
    dp[0][0] = 0;

    for (int i=0; i<v; ++i) {
        for (int j=0; j<e; ++j) {
            for (ll k=cost[j]; k<=m; ++k) {
                dp[b[j]][k] = min(dp[b[j]][k], dp[a[j]][k - cost[j]] + t[j]);
            }
        }
    }

    ll res = inf;
    rep(i, m+1) {
        res = min(res, dp[v][i]);
    }

    cout << (res == inf ? -1 : res) << endl;
}
0