結果

問題 No.844 split game
ユーザー tottoripapertottoripaper
提出日時 2019-07-03 23:21:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 173,452 KB
実行使用メモリ 17,332 KB
最終ジャッジ日時 2023-10-17 07:44:37
合計ジャッジ時間 7,687 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
11,000 KB
testcase_01 AC 25 ms
15,572 KB
testcase_02 AC 43 ms
12,156 KB
testcase_03 AC 39 ms
14,988 KB
testcase_04 AC 19 ms
10,784 KB
testcase_05 AC 54 ms
15,384 KB
testcase_06 AC 18 ms
10,956 KB
testcase_07 AC 20 ms
14,148 KB
testcase_08 AC 11 ms
9,832 KB
testcase_09 AC 33 ms
9,800 KB
testcase_10 AC 56 ms
14,260 KB
testcase_11 AC 58 ms
16,852 KB
testcase_12 AC 31 ms
9,524 KB
testcase_13 AC 21 ms
9,128 KB
testcase_14 AC 27 ms
13,352 KB
testcase_15 AC 62 ms
17,328 KB
testcase_16 AC 61 ms
17,324 KB
testcase_17 AC 61 ms
17,324 KB
testcase_18 AC 62 ms
17,332 KB
testcase_19 AC 63 ms
17,328 KB
testcase_20 AC 62 ms
17,328 KB
testcase_21 AC 63 ms
17,328 KB
testcase_22 AC 63 ms
17,324 KB
testcase_23 AC 6 ms
7,948 KB
testcase_24 AC 8 ms
8,444 KB
testcase_25 AC 5 ms
7,700 KB
testcase_26 AC 6 ms
7,980 KB
testcase_27 AC 7 ms
7,788 KB
testcase_28 AC 5 ms
8,164 KB
testcase_29 AC 7 ms
8,444 KB
testcase_30 AC 7 ms
8,420 KB
testcase_31 AC 6 ms
7,944 KB
testcase_32 AC 5 ms
8,064 KB
testcase_33 AC 7 ms
7,736 KB
testcase_34 AC 6 ms
7,644 KB
testcase_35 AC 8 ms
7,780 KB
testcase_36 AC 6 ms
7,664 KB
testcase_37 AC 10 ms
7,844 KB
testcase_38 AC 16 ms
8,768 KB
testcase_39 AC 32 ms
10,220 KB
testcase_40 AC 16 ms
12,152 KB
testcase_41 AC 4 ms
7,532 KB
testcase_42 AC 4 ms
7,532 KB
testcase_43 AC 4 ms
7,532 KB
testcase_44 AC 4 ms
7,532 KB
testcase_45 AC 4 ms
7,532 KB
testcase_46 AC 4 ms
7,532 KB
testcase_47 AC 4 ms
7,532 KB
testcase_48 AC 4 ms
7,532 KB
testcase_49 AC 4 ms
7,532 KB
testcase_50 AC 4 ms
7,532 KB
testcase_51 AC 4 ms
7,532 KB
testcase_52 AC 4 ms
7,532 KB
testcase_53 AC 4 ms
7,532 KB
testcase_54 AC 4 ms
7,532 KB
testcase_55 AC 4 ms
7,536 KB
testcase_56 AC 4 ms
7,536 KB
testcase_57 AC 4 ms
7,536 KB
testcase_58 AC 4 ms
7,536 KB
testcase_59 AC 4 ms
7,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M, A;
std::vector<P> v[100100];
ll dp[100100][2];

ll rec(int x, bool has){
    if(x == 0){
        return 0;
    }

    if(dp[x][has] != -1){
        return dp[x][has];
    }

    ll mx = rec(x - 1, 0);
    
    for(auto &pa : v[x]){
        int l, p;
        std::tie(l, p) = pa;

        mx = std::max(mx, rec(l, 1) + (has ? 0 : -A) + (l == 0 ? 0 : -A) + p);
    }

    return dp[x][has] = mx;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M >> A;

    for(int i=0;i<M;++i){
        int l, r, p;
        std::cin >> l >> r >> p;

        l -= 1;
        r -= 1;

        v[r+1].emplace_back(l, p);
    }

    memset(dp, -1, sizeof(dp));

    ll mx = rec(N, 1);
    std::cout << mx << std::endl;
}
0