結果

問題 No.974 最後の日までに
ユーザー HIR180HIR180
提出日時 2020-01-17 22:12:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 2,434 bytes
コンパイル時間 3,096 ms
コンパイル使用メモリ 200,460 KB
実行使用メモリ 11,748 KB
最終ジャッジ日時 2024-04-14 21:44:58
合計ジャッジ時間 9,661 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
11,488 KB
testcase_01 AC 134 ms
11,488 KB
testcase_02 AC 129 ms
11,492 KB
testcase_03 AC 116 ms
11,496 KB
testcase_04 AC 121 ms
11,616 KB
testcase_05 AC 132 ms
11,488 KB
testcase_06 AC 132 ms
11,484 KB
testcase_07 AC 119 ms
11,492 KB
testcase_08 AC 118 ms
11,748 KB
testcase_09 AC 120 ms
11,596 KB
testcase_10 AC 120 ms
11,612 KB
testcase_11 AC 116 ms
11,620 KB
testcase_12 AC 116 ms
11,616 KB
testcase_13 AC 118 ms
11,488 KB
testcase_14 AC 120 ms
11,616 KB
testcase_15 AC 114 ms
11,488 KB
testcase_16 AC 114 ms
11,488 KB
testcase_17 AC 110 ms
11,484 KB
testcase_18 AC 109 ms
11,484 KB
testcase_19 AC 110 ms
11,616 KB
testcase_20 AC 110 ms
11,616 KB
testcase_21 AC 108 ms
11,488 KB
testcase_22 AC 110 ms
11,612 KB
testcase_23 AC 110 ms
11,616 KB
testcase_24 AC 109 ms
11,612 KB
testcase_25 AC 32 ms
7,428 KB
testcase_26 AC 32 ms
7,300 KB
testcase_27 AC 117 ms
11,488 KB
testcase_28 AC 134 ms
11,612 KB
testcase_29 AC 32 ms
7,300 KB
testcase_30 AC 132 ms
11,680 KB
testcase_31 AC 32 ms
7,552 KB
testcase_32 AC 32 ms
7,300 KB
testcase_33 AC 98 ms
9,736 KB
testcase_34 AC 155 ms
11,616 KB
testcase_35 AC 32 ms
7,260 KB
testcase_36 AC 32 ms
7,204 KB
testcase_37 AC 142 ms
11,596 KB
testcase_38 AC 33 ms
7,428 KB
testcase_39 AC 32 ms
7,300 KB
testcase_40 AC 94 ms
11,488 KB
testcase_41 AC 110 ms
11,616 KB
testcase_42 AC 145 ms
11,620 KB
testcase_43 AC 139 ms
11,488 KB
testcase_44 AC 117 ms
11,616 KB
testcase_45 AC 102 ms
9,604 KB
testcase_46 AC 32 ms
7,304 KB
testcase_47 AC 32 ms
7,556 KB
testcase_48 AC 32 ms
7,296 KB
testcase_49 AC 32 ms
7,424 KB
testcase_50 AC 32 ms
7,300 KB
testcase_51 AC 32 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll a[60],b[60],c[60];
ll sum;
vector<pair<ll,ll>>V;
vector<int>mask[30];
ll ans;

void solve(){
	if(V.size() <= 10){
		for(int k=0;k<mask[V.size()].size();k++){
			ll gen = 0, gain = 0;
			rep(i,V.size()){
				int M = mask[V.size()][k];
				if(((M>>i)&1)){
					gen += V[i].fi;
					gain += V[i].sc;
				}
			}
			if(sum >= gen) ans = max(ans,gain);
		}
		cout << ans << endl;
		return ;
	}
	int nn = V.size()/2;
	int mm = V.size()-nn;
	vector<pair<ll,ll>>pr[2];
	rep(k,mask[nn].size()){
		ll genn = 0, gainn = 0;
		int f = 0;
		rep(i,nn){
			int M = mask[nn][k];
			if(((M>>i)&1)){
				if(i == nn-1) f = 1;
				genn += V[i].fi;
				gainn += V[i].sc;
			}
		}
		pr[f].pb(mp(genn,gainn));
	}
	rep(f,2) SORT(pr[f]);
	rep(f,2) for(int i=1;i<pr[f].size();i++) pr[f][i].sc = max(pr[f][i].sc,pr[f][i-1].sc);
	rep(k,mask[mm].size()){
		ll genn = 0, gainn = 0;
		int f = 0;
		rep(i,mm){
			int M = mask[mm][k];
			if(((M>>i)&1)){
				if(i == 0) f = 1;
				genn += V[nn+i].fi;
				gainn += V[nn+i].sc;
			}
		}
		int pt = POSL(pr[0],mp(sum-genn+1,(ll)-1e18));
		pt--;
		if(pt >= 0) ans = max(ans,pr[0][pt].sc+gainn);
		if(!f){
			int pt = POSL(pr[1],mp(sum-genn+1,(ll)-1e18));
			pt--;
			if(pt >= 0) ans = max(ans,pr[1][pt].sc+gainn);
		}
	}
	cout << ans << endl;
}
int main(){
	mask[0].pb(0);
	mask[1].pb(0); mask[1].pb(1);
	for(int i=2;i<=26;i++){
		for(int j=0;j<mask[i-1].size();j++){
			int cur = mask[i-1][j];
			mask[i].pb(cur);
			if(cur >= (1<<(i-2))){
				continue;
			}
			else mask[i].pb(mask[i-1][j] | (1<<(i-1)));
		}
		SORT(mask[i]); ERASE(mask[i]);
	}
	scanf("%d",&n);
	repn(i,n) scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
	repn(i,n) sum += a[i];
	for(int i=2;i<=n;i++){
		ll N = a[i-1]+a[i]+c[i];
		ll G = b[i];
		V.pb(mp(N,G));
	}
	solve();
}
0