結果

問題 No.1037 exhausted
ユーザー んんんんんん
提出日時 2023-01-05 17:01:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 4,788 ms
コンパイル使用メモリ 203,392 KB
実行使用メモリ 18,908 KB
最終ジャッジ日時 2023-08-19 14:20:58
合計ジャッジ時間 4,150 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,388 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 23 ms
18,596 KB
testcase_13 AC 20 ms
18,528 KB
testcase_14 AC 21 ms
18,528 KB
testcase_15 AC 21 ms
18,588 KB
testcase_16 AC 21 ms
18,824 KB
testcase_17 AC 23 ms
18,828 KB
testcase_18 AC 22 ms
18,588 KB
testcase_19 AC 22 ms
18,656 KB
testcase_20 AC 15 ms
18,656 KB
testcase_21 AC 15 ms
18,480 KB
testcase_22 AC 16 ms
18,908 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] = {0, 0, 0}; a[N+1] = {L, 0, 0};

    vector<vector<int>> dp(N+2, vector<int>(V+1, 1 << 30));
    dp[0][V] = 0;
    for (int i = 0; i < N+1; 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