結果

問題 No.1037 exhausted
ユーザー potoooooooopotoooooooo
提出日時 2020-04-24 22:32:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 169,684 KB
実行使用メモリ 35,332 KB
最終ジャッジ日時 2023-08-05 05:25:12
合計ジャッジ時間 2,774 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,072 KB
testcase_01 AC 11 ms
35,048 KB
testcase_02 AC 11 ms
35,004 KB
testcase_03 AC 11 ms
34,944 KB
testcase_04 AC 11 ms
34,940 KB
testcase_05 AC 11 ms
34,952 KB
testcase_06 AC 11 ms
34,944 KB
testcase_07 AC 11 ms
34,948 KB
testcase_08 AC 11 ms
34,944 KB
testcase_09 AC 11 ms
34,952 KB
testcase_10 AC 11 ms
35,148 KB
testcase_11 AC 11 ms
35,048 KB
testcase_12 AC 23 ms
35,060 KB
testcase_13 AC 23 ms
35,060 KB
testcase_14 AC 22 ms
35,016 KB
testcase_15 AC 22 ms
35,280 KB
testcase_16 AC 23 ms
35,332 KB
testcase_17 AC 23 ms
35,016 KB
testcase_18 AC 23 ms
35,016 KB
testcase_19 AC 23 ms
35,284 KB
testcase_20 AC 22 ms
35,208 KB
testcase_21 AC 11 ms
35,008 KB
testcase_22 AC 16 ms
35,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long c[2010][2010];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long N, V, L; cin >> N >> V >> L;
    vector<long long> x(N), v(N), w(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> v[i] >> w[i];
    x.emplace_back(L);
    memset(c, 1000000007, sizeof(c));
    long long inf = c[0][0];
    if (V < x[0]) {
        cout << -1 << "\n";
        return 0;
    }
    c[0][V-x[0]] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= V; j++) {
            int d = x[i+1] - x[i];
            if (d <= j) {
                c[i+1][j-d] = min(c[i+1][j-d], c[i][j]);
            }
            int k = min(V, j+v[i]);
            if (d <= k) {
                c[i+1][k-d] = min(c[i+1][k-d], c[i][j]+w[i]);
            }
        }
    }
    long long ans = inf;
    for (int i = 0; i <= V; i++) {
        ans = min(ans, c[N][i]);
    }
    ans = ans == inf ? -1 : ans;
    cout << ans << "\n";
    return 0;
}
0