結果

問題 No.844 split game
ユーザー face4face4
提出日時 2019-06-28 22:29:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 78,672 KB
実行使用メモリ 9,816 KB
最終ジャッジ日時 2023-09-14 22:18:13
合計ジャッジ時間 5,265 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
5,480 KB
testcase_01 AC 35 ms
8,044 KB
testcase_02 AC 88 ms
6,496 KB
testcase_03 AC 65 ms
8,212 KB
testcase_04 AC 32 ms
5,308 KB
testcase_05 AC 101 ms
8,328 KB
testcase_06 AC 31 ms
5,388 KB
testcase_07 AC 26 ms
7,236 KB
testcase_08 AC 16 ms
4,520 KB
testcase_09 AC 71 ms
5,120 KB
testcase_10 AC 107 ms
7,956 KB
testcase_11 AC 105 ms
9,460 KB
testcase_12 AC 71 ms
4,860 KB
testcase_13 AC 43 ms
4,476 KB
testcase_14 AC 45 ms
7,052 KB
testcase_15 AC 113 ms
9,816 KB
testcase_16 AC 111 ms
9,592 KB
testcase_17 AC 112 ms
9,576 KB
testcase_18 AC 112 ms
9,628 KB
testcase_19 AC 114 ms
9,592 KB
testcase_20 AC 115 ms
9,712 KB
testcase_21 AC 113 ms
9,712 KB
testcase_22 AC 113 ms
9,652 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 6 ms
4,384 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 6 ms
4,380 KB
testcase_35 AC 11 ms
4,376 KB
testcase_36 AC 7 ms
4,384 KB
testcase_37 AC 16 ms
4,380 KB
testcase_38 AC 30 ms
4,376 KB
testcase_39 AC 61 ms
4,912 KB
testcase_40 AC 20 ms
6,004 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

const ll INF = 1ll<<60;

int main(){
    int n, m, a;
    cin >> n >> m >> a;
    vector<pair<int,int>> vp[n+1];
    while(m-- > 0){
        int l, r, p;
        cin >> l >> r >> p;
        vp[l-1].push_back({r, p});
    }
    
    vector<vector<ll>> dp(2, vector<ll>(n+1, -INF));
    dp[0][0] = dp[1][0] = 0;
    for(int i = 0; i < n; i++){
        if(i){
            dp[0][i] = max({dp[0][i-1],dp[0][i],dp[1][i-1]});
            dp[1][i] = max(dp[1][i], dp[0][i]-a);
        }   
        for(pair<int,int> p : vp[i]){
            int r = p.first, val = p.second;
            int tmp = (r == n ? 0 : a);
            dp[1][r] = max({dp[1][r], dp[1][i]+val-tmp, dp[0][i]-a+val-tmp});
        }
    }
    
    // dirty :(
    ll ans = 0;
    for(int i = 0; i < 2; i++)  for(int j = 0; j <= n; j++) ans = max(ans,dp[i][j]);
    cout << ans << endl;

    return 0;
}
0