結果

問題 No.844 split game
ユーザー beetbeet
提出日時 2019-06-28 21:39:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 2,371 ms
コンパイル使用メモリ 203,404 KB
実行使用メモリ 11,272 KB
最終ジャッジ日時 2023-09-14 21:44:11
合計ジャッジ時間 6,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
6,152 KB
testcase_01 AC 34 ms
8,176 KB
testcase_02 AC 86 ms
8,292 KB
testcase_03 AC 63 ms
8,856 KB
testcase_04 AC 33 ms
5,752 KB
testcase_05 AC 100 ms
9,812 KB
testcase_06 AC 31 ms
5,692 KB
testcase_07 AC 25 ms
6,944 KB
testcase_08 AC 16 ms
4,532 KB
testcase_09 AC 73 ms
6,420 KB
testcase_10 AC 107 ms
9,936 KB
testcase_11 AC 110 ms
10,748 KB
testcase_12 AC 71 ms
6,312 KB
testcase_13 AC 45 ms
5,060 KB
testcase_14 AC 45 ms
7,280 KB
testcase_15 AC 110 ms
11,200 KB
testcase_16 AC 113 ms
11,244 KB
testcase_17 AC 111 ms
11,268 KB
testcase_18 AC 112 ms
11,248 KB
testcase_19 AC 111 ms
11,272 KB
testcase_20 AC 110 ms
11,124 KB
testcase_21 AC 112 ms
11,200 KB
testcase_22 AC 112 ms
11,168 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 9 ms
4,380 KB
testcase_31 AC 8 ms
4,380 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,380 KB
testcase_37 AC 17 ms
4,380 KB
testcase_38 AC 31 ms
4,904 KB
testcase_39 AC 65 ms
7,072 KB
testcase_40 AC 21 ms
6,300 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m,a;
  cin>>n>>m>>a;
  vector<Int> ls(m),rs(m),ps(m);
  for(Int i=0;i<m;i++) cin>>ls[i]>>rs[i]>>ps[i],ls[i]--;

  vector<vector<Int> > G(n+1);
  for(Int i=0;i<m;i++) G[rs[i]].emplace_back(i);

  const Int INF = 1e15;
  vector<Int> dp1(n+1,-INF);
  vector<Int> dp2(n+1,-INF);
  dp1[0]=dp2[0]=0;
  Int ans=0;
  for(Int i=1;i<=n;i++){
    chmax(dp2[i],dp2[i-1]);
    Int b=i==n?a:0;
    for(Int k:G[i]){
      chmax(dp1[i],dp1[ls[k]]+ps[k]-a+b);
      chmax(dp1[i],dp2[ls[k]]+ps[k]-a*2+b);
    }
    chmax(dp2[i],dp1[i]);
    chmax(ans,dp2[i]);
  }
  cout<<ans<<endl;
  return 0;
}
0