結果

問題 No.1037 exhausted
ユーザー veqccveqcc
提出日時 2020-04-24 22:26:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,256 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 107,652 KB
実行使用メモリ 34,524 KB
最終ジャッジ日時 2023-08-05 05:22:13
合計ジャッジ時間 2,646 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 39 ms
34,436 KB
testcase_13 AC 39 ms
34,116 KB
testcase_14 AC 40 ms
34,112 KB
testcase_15 AC 39 ms
34,496 KB
testcase_16 AC 39 ms
34,172 KB
testcase_17 AC 40 ms
34,520 KB
testcase_18 AC 41 ms
34,524 KB
testcase_19 AC 39 ms
34,520 KB
testcase_20 AC 35 ms
34,356 KB
testcase_21 AC 32 ms
34,376 KB
testcase_22 AC 26 ms
34,512 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