結果

問題 No.974 最後の日までに
ユーザー 沙耶花沙耶花
提出日時 2019-12-07 18:46:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 582 ms / 2,000 ms
コード長 2,560 bytes
コンパイル時間 2,569 ms
コンパイル使用メモリ 206,000 KB
実行使用メモリ 43,392 KB
最終ジャッジ日時 2024-04-14 21:43:07
合計ジャッジ時間 15,034 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 419 ms
43,136 KB
testcase_01 AC 458 ms
43,392 KB
testcase_02 AC 446 ms
43,392 KB
testcase_03 AC 445 ms
43,264 KB
testcase_04 AC 442 ms
43,264 KB
testcase_05 AC 442 ms
43,264 KB
testcase_06 AC 440 ms
43,136 KB
testcase_07 AC 453 ms
43,136 KB
testcase_08 AC 442 ms
43,264 KB
testcase_09 AC 480 ms
43,264 KB
testcase_10 AC 484 ms
43,392 KB
testcase_11 AC 494 ms
43,264 KB
testcase_12 AC 492 ms
43,136 KB
testcase_13 AC 483 ms
43,264 KB
testcase_14 AC 480 ms
43,136 KB
testcase_15 AC 503 ms
43,392 KB
testcase_16 AC 501 ms
43,136 KB
testcase_17 AC 29 ms
6,940 KB
testcase_18 AC 29 ms
6,940 KB
testcase_19 AC 28 ms
6,944 KB
testcase_20 AC 32 ms
6,940 KB
testcase_21 AC 32 ms
6,944 KB
testcase_22 AC 30 ms
6,940 KB
testcase_23 AC 29 ms
6,944 KB
testcase_24 AC 30 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 420 ms
35,712 KB
testcase_28 AC 529 ms
43,264 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 58 ms
6,944 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 317 ms
28,160 KB
testcase_34 AC 582 ms
43,136 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 87 ms
6,944 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 26 ms
6,944 KB
testcase_41 AC 30 ms
6,944 KB
testcase_42 AC 105 ms
6,940 KB
testcase_43 AC 102 ms
6,944 KB
testcase_44 AC 78 ms
6,940 KB
testcase_45 AC 67 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,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 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

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;
	}
	money+=a[ind];
	ind++;
	dfs1(a,b,c,ind,love,money);
	money-=a[ind-1];
	ind++;
	if(ind!=n+1){
		love+=b[ind-1];
		money-=c[ind-1];
		dfs1(a,b,c,ind,love,money);
		love-=b[ind-1];
		money+=c[ind-1];
	}
	else{
		dfs1(a,b,c,ind,love,money);
	}
	ind-=2;
}

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;
	}
	
	money+=a[ind];
	ind++;
	dfs2(a,b,c,ind,love,money,f);
	money-=a[ind-1];
	ind++;
	if(ind!=n+1){
		love+=b[ind-1];
		money-=c[ind-1];
		dfs2(a,b,c,ind,love,money,f);
		love-=b[ind-1];
		money+=c[ind-1];
	}
	else{
		dfs2(a,b,c,ind,love,money,f);
	}
	ind-=2;
}


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]);
		}
	}
	
	int ind;
	long long love;
	long long money;
	bool f;
	ind=0;
	love=0;
	money=0;
	f=true;
	
	dfs1(a1,b1,c1,ind,love,money);
	
	dfs2(a2,b2,c2,ind,love,money,f);
	f=false;
	ind=1;
	love=b2.front();
	money=-c2.front();
	
	if(b2.size()!=0){
		f=false;
		ind=1;
		love=b2.front();
		money=-c2.front();
		dfs2(a2,b2,c2,ind,love,money,f);
	}
	
	
	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