結果

問題 No.1037 exhausted
ユーザー んんんんんん
提出日時 2023-01-05 16:59:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 934 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 205,688 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-05-06 21:25:28
合計ジャッジ時間 4,442 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 RE -
testcase_03 AC 2 ms
5,376 KB
testcase_04 RE -
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 24 ms
18,816 KB
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 WA -
testcase_20 AC 17 ms
18,816 KB
testcase_21 AC 17 ms
18,944 KB
testcase_22 AC 20 ms
18,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int N, V, L;
    cin >> N >> V >> L;
    struct {
        int x;
        int v;
        int w;
    } a[N+2];
    for (int i = 1; i <= N; i++) {
        cin >> a[i].x >> a[i].v >> a[i].w;
    }
    a[0].x = 0; a[N+1].x = L;

    vector<vector<int>> dp(N+2, vector<int>(V+1, 1 << 30));
    dp[0][V] = 0;
    for (int i = 0; i < N+2; i++) {
        for (int j = 0; j <= V; j++) {
            if (dp[i][j] != 1 << 30 && a[i+1].x - a[i].x <= j) {
                dp[i+1][min(V, j-a[i+1].x+a[i].x+a[i+1].v)] =
                min(dp[i+1][min(V, j-a[i+1].x+a[i].x+a[i+1].v)], dp[i][j] + a[i+1].w);
                dp[i+1][j-a[i+1].x+a[i].x] =
                min(dp[i+1][j-a[i+1].x+a[i].x], dp[i][j]);
            }
        }
    }

    int ans = 1 << 30;
    for (int i = 0; i <= V; i++) ans = min(ans, dp[N+1][i]);
    if (ans == 1 << 30) ans = -1;
    cout << ans << endl;
}
0