結果

問題 No.1 道のショートカット
ユーザー Jikky1618
提出日時 2025-09-14 18:34:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,304 bytes
コンパイル時間 3,023 ms
コンパイル使用メモリ 288,516 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-14 18:34:35
合計ジャッジ時間 4,653 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

constexpr int INF = (1 << 30) - 1;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N, C, M;
    cin >> N >> C >> M;
    vector<int> S(M), T(M), Y(M), W(M);
    for (int i = 0; i < M; i++) cin >> S[i], S[i]--;
    for (int i = 0; i < M; i++) cin >> T[i], T[i]--;
    for (int i = 0; i < M; i++) cin >> Y[i];
    for (int i = 0; i < M; i++) cin >> W[i];
    vector<vector<tuple<int, int, int>>> G(N);
    for (int i = 0; i < M; i++) {
        // Y[i]: cost, W[i]: time
        G[S[i]].emplace_back(T[i], Y[i], W[i]);
    }

    // dp[c][i] := コスト c で頂点 i に到達するまでの最短時間
    vector dp(C + 1, vector<int>(N, INF));
    dp[0][0] = 0;

    for (int c = 0; c < C; c++) {
        for (int i = 0; i < N; i++) {
            if (dp[c][i] == INF) continue;
            for (auto [j, y, w] : G[i]) {
                if (c + y <= C) {
                    dp[c + y][j] = min(dp[c + y][j], dp[c][i] + w);
                }
            }
        }
    }

    int ans = INF;
    for (int c = 0; c <= C; c++) ans = min(ans, dp[c][N - 1]);
    cout << (ans == INF ? -1 : ans) << "\n";
}
0