結果

問題 No.1 道のショートカット
ユーザー H3PO4H3PO4
提出日時 2023-02-10 16:56:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,521 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 83,348 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-21 19:20:32
合計ジャッジ時間 3,785 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
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 WA -
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 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

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

    const int INF = 100000;

    std::vector<std::vector<int>> dp(N, std::vector<int>(C + 1, INF));
    dp.at(0).at(0) = 0;

    struct Edge {
        int t;
        int y;
        int m;
    };
    std::vector<std::vector<Edge>> G(N, std::vector<Edge>());
    for (int i = 0; i < N; i++) {
        Edge edge{T.at(i), Y.at(i), M.at(i)};
        G.at(S.at(i)).push_back(edge);
    }

    for (int s = 0; s < N; s++) {
        for (int c = 0; c < C; c++) {
            if (dp.at(s).at(c) == INF) {
                continue;
            }
            for (const auto &edge: G.at(s)) {
                if (c + edge.y > C) {
                    continue;
                }
                if (dp.at(edge.t).at(c + edge.y) > dp.at(s).at(c) + edge.m) {
                    dp.at(edge.t).at(c + edge.y) = dp.at(s).at(c) + edge.m;
                }
            }
        }
    }
    int ans = INF;
    for (const auto &x: dp.at(N - 1)) {
        if (ans > x) {
            ans = x;
        }
    }
    if (ans == INF) {
        ans = -1;
    }
    std::cout << ans << std::endl;
}
0