結果

問題 No.1037 exhausted
ユーザー 里旬里旬
提出日時 2020-04-24 23:13:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,422 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 199,480 KB
実行使用メモリ 34,900 KB
最終ジャッジ日時 2023-08-05 06:03:34
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 191 ms
34,680 KB
testcase_13 AC 192 ms
34,736 KB
testcase_14 AC 190 ms
34,616 KB
testcase_15 AC 192 ms
34,900 KB
testcase_16 AC 193 ms
34,600 KB
testcase_17 AC 191 ms
34,756 KB
testcase_18 AC 192 ms
34,600 KB
testcase_19 AC 193 ms
34,756 KB
testcase_20 AC 177 ms
34,576 KB
testcase_21 AC 131 ms
34,728 KB
testcase_22 AC 23 ms
34,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class segment_tree{
    int64_t tree[4002];
    size_t len;
public:
    segment_tree(int64_t n): len(n){ }
    void init(int64_t *val){
        for(int i=0;i<len;++i) tree[len+i] = val[i];
        for(int i=len-1;i>0;--i) tree[i] = min(tree[i<<1 | 0], tree[i<<1 | 1]);
    }
    int64_t get(int64_t left, int64_t right){
        left += len; right += len;
        int64_t ret = INT64_MAX;
        while(left < right){
            if(left & 1) ret = min(ret, tree[left++]);
            if(right & 1) ret = min(ret, tree[--right]);
            left >>= 1; right >>= 1;
        }
        return ret;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int64_t n, v, l, x[2002], a[2001], c[2001];
    cin >> n >> v >> l;
    x[0] = 0;
    for(int i=1;i<=n;++i) cin >> x[i] >> a[i] >> c[i];

    segment_tree st{v+1};
    static int64_t dp[2001][2001];
    for(int i=0;i<=v;++i) dp[0][i] = 0;
    for(int i=1;i<=n;++i){
        int64_t d = x[i] - x[i-1];
        st.init(dp[i-1]);
        for(int j=0;j<=v;++j){
            dp[i][j] = j+d<=v ? dp[i-1][j+d] : INT64_MAX;
            auto cand = st.get(max(j+d-a[i], d), min(j+d, v+1));
            if(cand < INT64_MAX) dp[i][j] = min(dp[i][j], cand + c[i]);
        }
    }
    st.init(dp[n]);
    auto ans = st.get(l-x[n], v+1);
    cout << (ans == INT64_MAX ? -1 : ans) << endl;

    return 0;
}
0