結果

問題 No.974 最後の日までに
ユーザー 沙耶花沙耶花
提出日時 2019-12-06 22:43:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 531 ms / 2,000 ms
コード長 2,107 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 175,660 KB
実行使用メモリ 43,392 KB
最終ジャッジ日時 2024-04-14 21:42:51
合計ジャッジ時間 13,832 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 406 ms
43,264 KB
testcase_01 AC 428 ms
43,264 KB
testcase_02 AC 431 ms
43,136 KB
testcase_03 AC 418 ms
43,264 KB
testcase_04 AC 418 ms
43,136 KB
testcase_05 AC 422 ms
43,264 KB
testcase_06 AC 421 ms
43,136 KB
testcase_07 AC 418 ms
43,136 KB
testcase_08 AC 408 ms
43,264 KB
testcase_09 AC 456 ms
43,136 KB
testcase_10 AC 449 ms
43,392 KB
testcase_11 AC 458 ms
43,264 KB
testcase_12 AC 448 ms
43,392 KB
testcase_13 AC 447 ms
43,264 KB
testcase_14 AC 444 ms
43,264 KB
testcase_15 AC 467 ms
43,264 KB
testcase_16 AC 464 ms
43,264 KB
testcase_17 AC 25 ms
6,940 KB
testcase_18 AC 24 ms
6,944 KB
testcase_19 AC 23 ms
6,944 KB
testcase_20 AC 25 ms
6,944 KB
testcase_21 AC 29 ms
6,940 KB
testcase_22 AC 27 ms
6,940 KB
testcase_23 AC 27 ms
6,940 KB
testcase_24 AC 26 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 413 ms
35,712 KB
testcase_28 AC 506 ms
43,392 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 55 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 297 ms
28,160 KB
testcase_34 AC 531 ms
43,136 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 91 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 22 ms
6,940 KB
testcase_41 AC 27 ms
6,940 KB
testcase_42 AC 109 ms
6,944 KB
testcase_43 AC 101 ms
6,944 KB
testcase_44 AC 79 ms
6,940 KB
testcase_45 AC 63 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

map<long long,long long> mp1,mp2,mp3,mp4;

void dfs1(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money){
	int n = a.size();
	if(ind==n){
		mp1[money] = max(mp1[money],love);
		return;
	}
	else if(ind==n+1){
		mp2[money] = max(mp2[money],love);
		return;
	}
	
	dfs1(a,b,c,ind+1,love,money+a[ind]);
	if(ind!=n-1)dfs1(a,b,c,ind+2,love+b[ind+1],money-c[ind+1]);
	else dfs1(a,b,c,ind+2,love,money);
}

void dfs2(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money,bool f){
	int n = a.size();
	if(ind==n){
		if(f)mp3[money] = max(mp3[money],love);
		else mp4[money] = max(mp4[money],love);
		return;
	}
	else if(ind==n+1){
		return;
	}
	
	dfs2(a,b,c,ind+1,love,money+a[ind],f);
	if(ind!=n-1)dfs2(a,b,c,ind+2,love+b[ind+1],money-c[ind+1],f);
	else dfs2(a,b,c,ind+2,love,money,f);
}


int main(){
	
	int D;
	cin>>D;
	
	vector<long long> a(D),b(D),c(D);
	
	for(int i=0;i<D;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	
	vector<long long> a1,a2,b1,b2,c1,c2;
	for(int i=0;i<D;i++){
		if(i<D/2){
			a1.push_back(a[i]);
			b1.push_back(b[i]);
			c1.push_back(c[i]);
		}
		else{
			a2.push_back(a[i]);
			b2.push_back(b[i]);
			c2.push_back(c[i]);
		}
	}
	
	dfs1(a1,b1,c1,0,0,0);
	
	dfs2(a2,b2,c2,0,0,0,true);
	
	if(b2.size()!=0)dfs2(a2,b2,c2,1,b2.front(),-c2.front(),false);
	
	long long last = 0;
	
	for(auto it = mp3.rbegin();it!=mp3.rend();it++){
		(*it).second = max((*it).second,last);
		last = (*it).second;
	}

	last=0;
	for(auto it = mp4.rbegin();it!=mp4.rend();it++){
		(*it).second = max((*it).second,last);
		last = (*it).second;
	}
	
	long long ans = 0;
	
	for(auto x:mp1){
		auto it = mp3.lower_bound(-x.first);
		if(it==mp3.end())continue;
		ans = max(ans,x.second + (*it).second);
	}
	
	for(auto x:mp2){
		auto it = mp4.lower_bound(-x.first);
		if(it==mp4.end())continue;
		ans = max(ans,x.second + (*it).second);
	}
	
	
	cout<<ans<<endl;
	

	return 0;
}
0