結果

問題 No.1037 exhausted
ユーザー sykwersykwer
提出日時 2020-04-25 00:58:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 2,215 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 116,356 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 04:31:16
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 13 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 13 ms
5,376 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 13 ms
5,376 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 12 ms
5,376 KB
testcase_22 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N, V, L;
    cin >> N >> V >> L;
    vector<int> x(N+2);
    vector<int> f(N+2);
    vector<int> w(N+2);
    for (int i = 1; i <= N ;i++) cin >> x[i] >> f[i] >> w[i];
    x[0] = 0;
    f[0] = 0;
    w[0] = 0;
    x[N+1] = L;
    f[N+1] = 0;
    w[N+1] = 0;

    vector<int> dp1(V+1, INF);
    vector<int> dp2(V+1, INF);
    vector<int> dp3(V+1, INF);
    dp1[V] = 0;

    for (int i = 0; i <= N; i++) {
        int dis = x[i+1] - x[i];
        dp2.assign(V+1, INF);
        for (int v = V; v >= 0; v--) {
            if (v - dis < 0) break;
            dp2[v-dis] = dp1[v];
        }

        dp3 = dp2;
        for (int v = 0; v <= V; v++) {
            chmin(dp3[min(V, v + f[i+1])], dp2[v] + w[i+1]);
        }

        swap(dp1, dp3);
    }

    int ret = INF;
    for (int d : dp1) ret = min(ret, d);
    if (ret == INF) ret = -1;
    cout << ret << endl;
    return 0;
}
0