結果

問題 No.1 道のショートカット
ユーザー satonakatakumisatonakatakumi
提出日時 2021-08-05 10:40:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,218 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 204,776 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 21:31:09
合計ジャッジ時間 4,984 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = std::int64_t;
using vi64 = std::vector<i64>;
using vvi64 = std::vector<vi64>;

int main() {
    using namespace std;
    const i64 inf = 1e9;
    i64 n, c, v;
    cin >> n >> c >> v;
    vi64 s(v);
    for (i64 i = 0; i < v; i++) {
        cin >> s[i];
        s[i]--;
    }
    vvi64 t(n), y(n), m(n);
    i64 x;
    for (i64 i = 0; i < v; i++) {
        cin >> x;
        x--;
        t[s[i]].push_back(x);
    }
    for (i64 i = 0; i < v; i++) {
        cin >> x;
        y[s[i]].push_back(x);
    }
    for (i64 i = 0; i < v; i++) {
        cin >> x;
        m[s[i]].push_back(x);
    }
    vvi64 dp(n, vi64(c + 1, inf));
    dp[0][c] = 0;
    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < (c + 1); j++) {
            if (dp[i][j] == inf) continue;
            for (i64 k = 0; k < t[i].size(); k++) {
                i64 to = t[i][k], cost = j - y[i][k];
                if (cost >= 0) {
                    dp[to][cost] = min(dp[to][cost], dp[i][j] + m[i][k]);
                }
            }
        }
    }
    i64 ans = inf;
    for (i64 i = 0; i < (c + 1); i++) ans = min(ans, dp[n - 1][i]);
    if (ans == inf) cout << "-1\n";
    else cout << ans << '\n';
}
0