結果

問題 No.974 最後の日までに
ユーザー chocoruskchocorusk
提出日時 2020-01-17 22:48:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,208 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 118,500 KB
実行使用メモリ 19,332 KB
最終ジャッジ日時 2023-09-08 05:51:13
合計ジャッジ時間 39,420 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 973 ms
16,340 KB
testcase_02 AC 973 ms
17,788 KB
testcase_03 AC 957 ms
17,412 KB
testcase_04 AC 994 ms
16,876 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 996 ms
16,460 KB
testcase_10 AC 993 ms
16,496 KB
testcase_11 AC 991 ms
17,080 KB
testcase_12 AC 975 ms
17,956 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 981 ms
17,248 KB
testcase_16 AC 950 ms
16,580 KB
testcase_17 AC 975 ms
17,392 KB
testcase_18 AC 992 ms
16,420 KB
testcase_19 AC 996 ms
16,448 KB
testcase_20 AC 972 ms
17,712 KB
testcase_21 AC 971 ms
16,832 KB
testcase_22 AC 967 ms
16,540 KB
testcase_23 AC 971 ms
16,440 KB
testcase_24 AC 982 ms
18,544 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 837 ms
14,864 KB
testcase_28 AC 987 ms
16,720 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1,009 ms
16,796 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 504 ms
11,460 KB
testcase_34 AC 980 ms
16,832 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 818 ms
14,556 KB
testcase_41 AC 948 ms
16,572 KB
testcase_42 AC 984 ms
16,920 KB
testcase_43 AC 1,005 ms
16,884 KB
testcase_44 AC 850 ms
15,596 KB
testcase_45 AC 504 ms
10,780 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 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