結果

問題 No.1037 exhausted
ユーザー micheeeeell1001micheeeeell1001
提出日時 2020-04-24 23:00:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 2,310 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 201,420 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2024-04-23 04:06:16
合計ジャッジ時間 3,066 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 41 ms
34,816 KB
testcase_13 AC 42 ms
34,688 KB
testcase_14 AC 41 ms
34,816 KB
testcase_15 AC 41 ms
34,816 KB
testcase_16 AC 41 ms
34,816 KB
testcase_17 AC 40 ms
34,688 KB
testcase_18 AC 41 ms
34,944 KB
testcase_19 AC 39 ms
34,688 KB
testcase_20 AC 39 ms
34,688 KB
testcase_21 AC 38 ms
34,816 KB
testcase_22 AC 37 ms
34,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void print() {
    cout << endl;
}

// template <class Head, class... Tail>
// void print(Head&& head, Tail&&... tail) {
//     cout << head;
//     if (sizeof...(tail) != 0) cout << " ";
//     print(forward<Tail>(tail)...);
// }

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i,k-1)cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,V,l; cin >> n >> V >> l;
    vector<ll> x(n+1), v(n), w(n);
    x[0] = 0;
    rep(i,n){
        cin >> x[i+1] >> v[i] >> w[i];
    }
    vector<vector<ll>> dp(n+10, vector<ll>(V+10, INF));
    rep(i,V+1)dp[0][i] = 0;
    rep(i,n){
        rrep(j,V+1){
            if(j + x[i+1] - x[i] < V+1)chmin(dp[i+1][j], dp[i][j + x[i+1] - x[i]]);
        }
        rrep(j,V+1){
            chmin(dp[i+1][j], dp[i+1][max(0LL, j - v[i])] + w[i]);
            chmin(dp[i+1][j], dp[i+1][j+1]);
        }
    }

    // print(dp);
    if(l - x[n] > V){
        cout << -1 << endl;
        return 0;
    }
    cout << (dp[n][l-x[n]] == INF ? -1 : dp[n][l-x[n]]) << endl;
}
0