結果

問題 No.1037 exhausted
ユーザー veqccveqcc
提出日時 2020-04-24 22:26:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,256 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 109,600 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-04-23 03:37:53
合計ジャッジ時間 1,907 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 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 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 33 ms
34,432 KB
testcase_13 AC 33 ms
34,432 KB
testcase_14 AC 33 ms
34,432 KB
testcase_15 AC 32 ms
34,688 KB
testcase_16 AC 31 ms
34,560 KB
testcase_17 AC 32 ms
34,688 KB
testcase_18 AC 32 ms
34,432 KB
testcase_19 AC 32 ms
34,560 KB
testcase_20 AC 29 ms
34,304 KB
testcase_21 AC 27 ms
34,560 KB
testcase_22 AC 25 ms
34,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MX = 1LL << 60;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n, V, l;
    cin >> n >> V >> l;

    vector <ll> x(n + 1, 0), v(n), w(n);
    for (int i = 0; i < n; i++) cin >> x[i + 1] >> v[i] >> w[i];

    // dp[i][j]: i番目のガソスタまで行って、燃料がjの時の最小費用
    vector < vector <ll> > dp(n + 1, vector<ll>(V + 1, MX));
    dp[0][V] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = x[i + 1] - x[i]; j <= V; j++) {
            ll nxt_v = j - (x[i + 1] - x[i]);
            dp[i + 1][nxt_v] = min(dp[i + 1][nxt_v], dp[i][j]);

            nxt_v = min(V, nxt_v + v[i]);
            dp[i + 1][nxt_v] = min(dp[i + 1][nxt_v], dp[i][j] + w[i]);
        }
    }

    ll ans = 1LL << 60;
    for (int j = l - x[n]; j <= V; j++) {
        if (dp[n][j] < MX) {
            ans = min(ans, dp[n][j]);
        }
    }

    cout << (ans == MX ? -1 : ans) << "\n";
    return 0;
}
0