結果

問題 No.1037 exhausted
ユーザー finefine
提出日時 2020-04-25 02:02:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 1,467 ms
コンパイル使用メモリ 167,880 KB
実行使用メモリ 34,560 KB
最終ジャッジ日時 2024-04-23 13:41:48
合計ジャッジ時間 2,584 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 32 ms
34,560 KB
testcase_13 AC 31 ms
34,432 KB
testcase_14 AC 32 ms
34,304 KB
testcase_15 AC 31 ms
34,560 KB
testcase_16 AC 32 ms
34,304 KB
testcase_17 AC 31 ms
34,432 KB
testcase_18 AC 30 ms
34,560 KB
testcase_19 AC 29 ms
34,432 KB
testcase_20 AC 28 ms
34,560 KB
testcase_21 AC 26 ms
34,560 KB
testcase_22 AC 23 ms
34,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll INF = 1e17;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, V, L;
    cin >> n >> V >> L;

    vector< vector<ll> > dp(n + 1, vector<ll>(V + 1, INF));
    dp[0][V] = 0;
    int prvx = 0;
    for (int i = 0; i < n; ++i) {
        int x, v;
        ll w;
        cin >> x >> v >> w;
        
        int hoge = x - prvx;
        for (int j = hoge; j <= V; ++j) {
            dp[i + 1][j - hoge] = min(dp[i + 1][j - hoge], dp[i][j]);
            ll& tar = dp[i + 1][min(j - hoge + v, V)]; 
            tar = min(tar, dp[i][j] + w);
        }
        prvx = x;
    }

    ll foo = L - prvx;
    ll ans = INF;
    for (ll i = foo; i <= V; ++i) {
        ans = min(ans, dp[n][i]);
    }
    cout << (ans >= INF ? -1 : ans) << "\n";
    return 0;
}
0