結果

問題 No.1 道のショートカット
ユーザー hellohello
提出日時 2014-11-13 22:06:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 623 ms / 5,000 ms
コード長 909 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 64,092 KB
実行使用メモリ 5,416 KB
最終ジャッジ日時 2023-09-27 21:36:08
合計ジャッジ時間 6,338 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,072 KB
testcase_01 AC 3 ms
5,096 KB
testcase_02 AC 3 ms
5,100 KB
testcase_03 AC 3 ms
5,156 KB
testcase_04 AC 3 ms
5,144 KB
testcase_05 AC 3 ms
5,096 KB
testcase_06 AC 3 ms
5,136 KB
testcase_07 AC 3 ms
5,324 KB
testcase_08 AC 373 ms
5,172 KB
testcase_09 AC 130 ms
5,076 KB
testcase_10 AC 96 ms
5,160 KB
testcase_11 AC 208 ms
5,116 KB
testcase_12 AC 623 ms
5,416 KB
testcase_13 AC 602 ms
5,172 KB
testcase_14 AC 5 ms
5,200 KB
testcase_15 AC 4 ms
5,260 KB
testcase_16 AC 19 ms
5,236 KB
testcase_17 AC 3 ms
5,200 KB
testcase_18 AC 5 ms
5,100 KB
testcase_19 AC 7 ms
5,080 KB
testcase_20 AC 19 ms
5,160 KB
testcase_21 AC 15 ms
5,088 KB
testcase_22 AC 7 ms
5,064 KB
testcase_23 AC 469 ms
5,156 KB
testcase_24 AC 434 ms
5,216 KB
testcase_25 AC 41 ms
5,084 KB
testcase_26 AC 20 ms
5,084 KB
testcase_27 AC 325 ms
5,096 KB
testcase_28 AC 4 ms
5,364 KB
testcase_29 AC 89 ms
5,120 KB
testcase_30 AC 8 ms
5,100 KB
testcase_31 AC 36 ms
5,140 KB
testcase_32 AC 178 ms
5,396 KB
testcase_33 AC 97 ms
5,168 KB
testcase_34 AC 341 ms
5,104 KB
testcase_35 AC 9 ms
5,096 KB
testcase_36 AC 49 ms
5,176 KB
testcase_37 AC 10 ms
5,164 KB
testcase_38 AC 4 ms
5,080 KB
testcase_39 AC 11 ms
5,096 KB
testcase_40 AC 8 ms
5,092 KB
testcase_41 AC 4 ms
5,264 KB
testcase_42 AC 3 ms
5,292 KB
testcase_43 AC 4 ms
5,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1e6;
int N, C, V;
int dp[1501][301];

int main() {
    cin >> N >> C >> V;
    vector<int> S(V), T(V), Y(V), M(V);
    for (int i=0; i<V; ++i) cin >> S[i];
    for (int i=0; i<V; ++i) cin >> T[i];
    for (int i=0; i<V; ++i) cin >> Y[i];
    for (int i=0; i<V; ++i) cin >> M[i];

    for (int i=0; i<1501; ++i) {
        for (int j=0; j<=C; ++j) {
            dp[i][j] = INF;
        }
    }
    dp[1][0] = 0;
    for (int k=0; k<V; ++k) {
        for (int i=0; i<V; ++i) {
            for (int j=0; j+Y[i]<=C; ++j) {
                dp[T[i]][j+Y[i]] = min(dp[T[i]][j+Y[i]], dp[S[i]][j]+M[i]);
            }
        }
    }
    int ans = INF;
    for (int i=0; i<=C; ++i) {
        ans = min(ans, dp[N][i]);
    }
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}
0