結果

問題 No.844 split game
ユーザー furafura
提出日時 2020-06-01 14:20:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 216,632 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 13:12:26
合計ジャッジ時間 5,495 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
6,812 KB
testcase_01 AC 22 ms
6,940 KB
testcase_02 AC 64 ms
6,944 KB
testcase_03 AC 46 ms
6,944 KB
testcase_04 AC 25 ms
6,944 KB
testcase_05 AC 64 ms
6,940 KB
testcase_06 AC 20 ms
6,944 KB
testcase_07 AC 16 ms
6,940 KB
testcase_08 AC 11 ms
6,940 KB
testcase_09 AC 52 ms
6,940 KB
testcase_10 AC 73 ms
6,940 KB
testcase_11 AC 66 ms
6,940 KB
testcase_12 AC 49 ms
6,940 KB
testcase_13 AC 30 ms
6,944 KB
testcase_14 AC 28 ms
6,944 KB
testcase_15 AC 77 ms
6,940 KB
testcase_16 AC 79 ms
6,944 KB
testcase_17 AC 75 ms
6,940 KB
testcase_18 AC 73 ms
6,940 KB
testcase_19 AC 78 ms
6,940 KB
testcase_20 AC 77 ms
6,944 KB
testcase_21 AC 77 ms
6,940 KB
testcase_22 AC 75 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 7 ms
6,940 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 6 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 6 ms
6,944 KB
testcase_30 AC 7 ms
6,944 KB
testcase_31 AC 6 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 7 ms
6,940 KB
testcase_34 AC 5 ms
6,944 KB
testcase_35 AC 8 ms
6,940 KB
testcase_36 AC 5 ms
6,944 KB
testcase_37 AC 12 ms
6,940 KB
testcase_38 AC 23 ms
6,944 KB
testcase_39 AC 50 ms
6,944 KB
testcase_40 AC 15 ms
6,944 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 1 ms
6,940 KB
testcase_46 AC 1 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 1 ms
6,944 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
testcase_52 AC 1 ms
6,944 KB
testcase_53 AC 1 ms
6,940 KB
testcase_54 AC 2 ms
6,940 KB
testcase_55 AC 1 ms
6,944 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 AC 2 ms
6,940 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T> struct interval{
	T l,r;
	int wt;
	interval(){}
	interval(const T& l,const T& r,int wt):l(l),r(r),wt(wt){}
	bool operator<(const interval& I)const{ return make_tuple(r,l)<make_tuple(I.r,I.l); }
};

const long long INF=1LL<<61;

int main(){
	int L,m,c; scanf("%d%d%d",&L,&m,&c);
	vector<interval<int>> I(m);
	rep(i,m) scanf("%d%d%d",&I[i].l,&I[i].r,&I[i].wt), I[i].r++;

	vector<int> X={0,1,L+1};
	rep(i,m){
		X.emplace_back(I[i].l);
		X.emplace_back(I[i].r);
	}
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());

	rep(i,m){
		I[i].l=lower_bound(X.begin(),X.end(),I[i].l)-X.begin();
		I[i].r=lower_bound(X.begin(),X.end(),I[i].r)-X.begin();
	}

	sort(I.begin(),I.end());

	int n=X.size(),idx=0;
	// dp[i] = ([1, X[i]) に含まれる区間だけを考えて, X[i] の左に区切りを入れたときのスコアの最大値)
	vector<lint> dp(n,-INF),dp_max(n,-INF);
	dp[1]=0;
	dp_max[1]=0;
	for(int i=2;i<n;i++){
		while(idx<m && I[idx].r==i){
			dp[i]=max(dp[i],dp[I[idx].l]+I[idx].wt-(i<n-1?c:0));
			dp[i]=max(dp[i],dp_max[I[idx].l-1]+I[idx].wt-(i<n-1?2*c:c));
			idx++;
		}
		dp_max[i]=max(dp_max[i-1],dp[i]);
	}
	printf("%lld\n",dp_max[n-1]);

	return 0;
}
0