結果

問題 No.974 最後の日までに
ユーザー chocoruskchocorusk
提出日時 2020-01-17 23:18:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 687 ms / 2,000 ms
コード長 2,223 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 120,088 KB
実行使用メモリ 17,812 KB
最終ジャッジ日時 2024-04-14 21:51:09
合計ジャッジ時間 26,877 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 646 ms
16,732 KB
testcase_01 AC 675 ms
16,656 KB
testcase_02 AC 651 ms
16,656 KB
testcase_03 AC 659 ms
17,556 KB
testcase_04 AC 668 ms
17,296 KB
testcase_05 AC 655 ms
16,916 KB
testcase_06 AC 645 ms
17,104 KB
testcase_07 AC 662 ms
16,656 KB
testcase_08 AC 651 ms
16,660 KB
testcase_09 AC 675 ms
17,080 KB
testcase_10 AC 658 ms
16,784 KB
testcase_11 AC 652 ms
17,632 KB
testcase_12 AC 653 ms
16,656 KB
testcase_13 AC 677 ms
17,812 KB
testcase_14 AC 674 ms
16,864 KB
testcase_15 AC 662 ms
17,512 KB
testcase_16 AC 667 ms
16,780 KB
testcase_17 AC 663 ms
16,732 KB
testcase_18 AC 653 ms
16,784 KB
testcase_19 AC 687 ms
17,424 KB
testcase_20 AC 647 ms
16,784 KB
testcase_21 AC 654 ms
17,616 KB
testcase_22 AC 662 ms
16,788 KB
testcase_23 AC 672 ms
17,652 KB
testcase_24 AC 664 ms
16,784 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 499 ms
14,892 KB
testcase_28 AC 654 ms
17,264 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 665 ms
16,660 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 353 ms
11,604 KB
testcase_34 AC 662 ms
16,952 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 683 ms
16,784 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 518 ms
15,020 KB
testcase_41 AC 644 ms
17,216 KB
testcase_42 AC 645 ms
17,552 KB
testcase_43 AC 664 ms
17,272 KB
testcase_44 AC 518 ms
14,508 KB
testcase_45 AC 338 ms
11,604 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 1 ms
6,944 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 1 ms
6,940 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<=2){
		cout<<0<<endl;
		return 0;
	}
	vector<P> v1, v2, v11, v22;
	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))!=0 && (i&(1<<(j-1)))!=0){
				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)))==0) v11.push_back({xs, bs});
	}
	for(int i=0; i<(1<<(w-w/2)); i+=2){
		bool dame=0;
		for(int j=1; j<w-w/2; j++){
			if((i&(1<<j))!=0 && (i&(1<<(j-1)))!=0){
				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});
		if(!(i&2)) v22.push_back({xs, bs});
	}
	sort(v1.begin(), v1.end());
	sort(v11.begin(), v11.end());
	sort(v2.begin(), v2.end());
	sort(v22.begin(), v22.end());
	for(int i=1; i<v2.size(); i++){
		v2[i].second=max(v2[i].second, v2[i-1].second);
	}
	for(int i=1; i<v22.size(); i++){
		v22[i].second=max(v22[i].second, v22[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(v22.begin(), v22.end(), P(sa-p.first-x[w/2], 1e18))-v22.begin();
		if(k==0) continue;
		ans=max(ans, p.second+v22[k-1].second+b[w/2]);
	}
	cout<<ans<<endl;
	return 0;
}
0