結果

問題 No.974 最後の日までに
ユーザー chocoruskchocorusk
提出日時 2020-01-17 22:49:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,212 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 117,908 KB
実行使用メモリ 19,180 KB
最終ジャッジ日時 2023-09-08 05:58:04
合計ジャッジ時間 39,629 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 996 ms
16,648 KB
testcase_02 AC 996 ms
17,948 KB
testcase_03 AC 994 ms
17,224 KB
testcase_04 AC 998 ms
17,076 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 993 ms
16,888 KB
testcase_10 AC 992 ms
16,608 KB
testcase_11 AC 993 ms
17,160 KB
testcase_12 AC 995 ms
17,452 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 993 ms
17,288 KB
testcase_16 AC 993 ms
18,172 KB
testcase_17 AC 997 ms
16,428 KB
testcase_18 AC 1,001 ms
16,808 KB
testcase_19 AC 1,001 ms
16,892 KB
testcase_20 AC 1,000 ms
16,824 KB
testcase_21 AC 999 ms
16,880 KB
testcase_22 AC 1,000 ms
17,440 KB
testcase_23 AC 999 ms
17,436 KB
testcase_24 AC 997 ms
16,288 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 846 ms
16,076 KB
testcase_28 AC 1,000 ms
16,628 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1,016 ms
17,004 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 515 ms
10,768 KB
testcase_34 AC 998 ms
16,588 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 WA -
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 833 ms
15,276 KB
testcase_41 AC 987 ms
17,316 KB
testcase_42 AC 1,005 ms
16,760 KB
testcase_43 AC 1,008 ms
19,180 KB
testcase_44 AC 851 ms
15,364 KB
testcase_45 AC 520 ms
11,820 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
	int w;
	cin>>w;
	ll a[55], b[55], c[55], x[55];
	ll sa=0;
	for(int i=0; i<w; i++){
		cin>>a[i]>>b[i]>>c[i];
		sa+=a[i];
	}
	for(int i=1; i<w; i++){
		x[i]=a[i]+a[i-1]+c[i];
	}
	if(w==1){
		cout<<0<<endl;
		return 0;
	}
	vector<P> v1, v2, v11;
	for(int i=0; i<(1<<(w/2)); i+=2){
		bool dame=0;
		for(int j=1; j<w/2; j++){
			if(i&(1<<j) && i&(1<<(j-1))){
				dame=1; break;
			}
		}
		if(dame) continue;
		ll xs=0, bs=0;
		for(int j=1; j<w/2; j++){
			if(i&(1<<j)){
				xs+=x[j], bs+=b[j];
			}
		}
		v1.push_back({xs, bs});
		if(!(i&(1<<(w/2-1)))) v11.push_back({xs, bs});
	}
	for(int i=0; i<(1<<(w-w/2)); i++){
		bool dame=0;
		for(int j=1; j<w-w/2; j++){
			if(i&(1<<j) && i&(1<<(j-1))){
				dame=1; break;
			}
		}
		if(dame) continue;
		ll xs=0, bs=0;
		for(int j=1; j<w-w/2; j++){
			if(i&(1<<j)){
				xs+=x[w/2+j], bs+=b[w/2+j];
			}
		}
		v2.push_back({xs, bs});
	}
	sort(v1.begin(), v1.end());
	sort(v11.begin(), v11.end());
	sort(v2.begin(), v2.end());
	/*for(int i=1; i<v1.size(); i++){
		v1[i].second=max(v1[i].second, v1[i-1].second);
	}
	for(int i=1; i<v11.size(); i++){
		v11[i].second=max(v11[i].second, v11[i-1].second);
	}*/
	for(int i=1; i<v2.size(); i++){
		v2[i].second=max(v2[i].second, v2[i-1].second);
	}
	ll ans=0;
	for(auto p:v1){
		if(p.first>sa) continue;
		int k=upper_bound(v2.begin(), v2.end(), P(sa-p.first, 1e18))-v2.begin();
		if(k==0) continue;
		ans=max(ans, p.second+v2[k-1].second);
	}
	for(auto p:v11){
		if(p.first>sa-x[w/2]) continue;
		int k=upper_bound(v2.begin(), v2.end(), P(sa-p.first-x[w/2], 1e18))-v2.begin();
		if(k==0) continue;
		ans=max(ans, p.second+v2[k-1].second+b[w/2]);
	}
	cout<<ans<<endl;
	return 0;
}
0