結果

問題 No.974 最後の日までに
ユーザー 沙耶花沙耶花
提出日時 2019-12-11 14:19:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 2,325 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 208,028 KB
実行使用メモリ 16,520 KB
最終ジャッジ日時 2024-04-14 21:43:46
合計ジャッジ時間 6,816 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
16,176 KB
testcase_01 AC 73 ms
15,900 KB
testcase_02 AC 71 ms
15,688 KB
testcase_03 AC 72 ms
16,028 KB
testcase_04 AC 77 ms
15,936 KB
testcase_05 AC 73 ms
16,316 KB
testcase_06 AC 71 ms
15,672 KB
testcase_07 AC 76 ms
15,980 KB
testcase_08 AC 74 ms
15,608 KB
testcase_09 AC 81 ms
16,020 KB
testcase_10 AC 80 ms
16,444 KB
testcase_11 AC 84 ms
16,120 KB
testcase_12 AC 82 ms
15,260 KB
testcase_13 AC 81 ms
15,268 KB
testcase_14 AC 80 ms
15,356 KB
testcase_15 AC 81 ms
15,204 KB
testcase_16 AC 84 ms
16,448 KB
testcase_17 AC 72 ms
16,520 KB
testcase_18 AC 73 ms
16,316 KB
testcase_19 AC 71 ms
15,552 KB
testcase_20 AC 71 ms
15,200 KB
testcase_21 AC 72 ms
15,936 KB
testcase_22 AC 71 ms
15,292 KB
testcase_23 AC 71 ms
15,764 KB
testcase_24 AC 72 ms
15,272 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 78 ms
13,768 KB
testcase_28 AC 85 ms
15,160 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 85 ms
15,376 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 57 ms
11,352 KB
testcase_34 AC 99 ms
16,316 KB
testcase_35 AC 2 ms
6,948 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 96 ms
15,800 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 57 ms
13,940 KB
testcase_41 AC 63 ms
15,312 KB
testcase_42 AC 95 ms
15,408 KB
testcase_43 AC 98 ms
15,400 KB
testcase_44 AC 82 ms
13,356 KB
testcase_45 AC 59 ms
11,224 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,940 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

vector<pair<long long,long long>> V1,V2,V3,V4;

void dfs1(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money,bool flag){
	int n = a.size();
	if(ind==n){
		if(flag) V2.emplace_back(money,love);
		else V1.emplace_back(money,love);
		return;
	}
	
	if(flag){
		dfs1(a,b,c,ind+1,love+b[ind],money-c[ind],false);
	}
	else{
		dfs1(a,b,c,ind+1,love,money+a[ind],false);
		dfs1(a,b,c,ind+1,love,money,true);
	}

}

void dfs2(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money,bool f,bool flag){
	int n = a.size();
	if(ind==n){
		if(flag)return;
		if(f)V3.emplace_back(money,love);
		else V4.emplace_back(money,love);
		return;
	}
	
	if(flag){
		dfs2(a,b,c,ind+1,love+b[ind],money-c[ind],f,false);
	}
	else{
		dfs2(a,b,c,ind+1,love,money+a[ind],f,false);
		dfs2(a,b,c,ind+1,love,money,f,true);
	}
	
}


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,false);
	
	dfs2(a2,b2,c2,0,0,0,true,false);
	
	if(b2.size()!=0)dfs2(a2,b2,c2,0,0,0,false,true);
	
	sort(V3.begin(),V3.end());
	sort(V4.begin(),V4.end());
	
	long long last = 0;
	
	for(auto it = V3.rbegin();it!=V3.rend();it++){
		(*it).second = max((*it).second,last);
		last = (*it).second;
	}

	last=0;
	for(auto it = V4.rbegin();it!=V4.rend();it++){
		(*it).second = max((*it).second,last);
		last = (*it).second;
	}
	
	long long ans = 0;
	pair<long long,long long> P = make_pair(0,-Inf);
	for(int i=0;i<V1.size();i++){
		P.first = -V1[i].first;
		auto it = lower_bound(V3.begin(),V3.end(),P);
		if(it==V3.end())continue;
		ans = max(ans,V1[i].second + (*it).second);
	}
	
	for(int i=0;i<V2.size();i++){
		P.first = -V2[i].first;
		auto it = lower_bound(V4.begin(),V4.end(),P);
		if(it==V4.end())continue;
		ans = max(ans,V2[i].second + (*it).second);
	}
	
	
	cout<<ans<<endl;
	

	return 0;
}
0