結果

問題 No.974 最後の日までに
ユーザー leaf_1415leaf_1415
提出日時 2020-01-18 04:53:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,678 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 71,792 KB
実行使用メモリ 22,220 KB
最終ジャッジ日時 2023-07-27 09:16:49
合計ジャッジ時間 7,676 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
22,144 KB
testcase_01 AC 94 ms
21,540 KB
testcase_02 AC 90 ms
20,188 KB
testcase_03 AC 91 ms
21,348 KB
testcase_04 AC 93 ms
20,232 KB
testcase_05 AC 91 ms
20,992 KB
testcase_06 AC 91 ms
21,284 KB
testcase_07 AC 93 ms
21,808 KB
testcase_08 AC 93 ms
22,220 KB
testcase_09 AC 110 ms
21,368 KB
testcase_10 AC 106 ms
20,452 KB
testcase_11 AC 106 ms
21,804 KB
testcase_12 AC 105 ms
20,808 KB
testcase_13 AC 109 ms
20,100 KB
testcase_14 AC 109 ms
21,660 KB
testcase_15 AC 105 ms
21,596 KB
testcase_16 AC 106 ms
22,028 KB
testcase_17 AC 93 ms
21,924 KB
testcase_18 AC 93 ms
22,176 KB
testcase_19 AC 94 ms
21,156 KB
testcase_20 AC 93 ms
21,276 KB
testcase_21 AC 94 ms
21,504 KB
testcase_22 AC 95 ms
21,580 KB
testcase_23 AC 93 ms
20,608 KB
testcase_24 AC 93 ms
21,892 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 99 ms
18,580 KB
testcase_28 AC 108 ms
22,064 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 120 ms
21,872 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 71 ms
13,924 KB
testcase_34 AC 125 ms
20,508 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 125 ms
21,484 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 73 ms
19,272 KB
testcase_41 AC 83 ms
20,864 KB
testcase_42 AC 128 ms
20,648 KB
testcase_43 AC 129 ms
21,520 KB
testcase_44 AC 115 ms
19,216 KB
testcase_45 AC 78 ms
14,048 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[55], b[55], c[55];
vector<P> vec[2], vec2[2];
vector<llint> maxvec[2];

void dfs(llint d, llint m, llint l, llint p)
{
	if(d == n/2+1){
		vec[p].push_back(P(m, l));
		return;
	}
	if(p == 0){
		dfs(d+1, m+a[d], l, 0);
		dfs(d+1, m, l, 1);
	}
	else dfs(d+1, m-c[d], l+b[d], 0);
}

void dfs2(llint d, llint m, llint l, llint p, llint s)
{
	if(d == n+1){
		vec2[s].push_back(P(m, l));
		return;
	}
	if(d == n/2+1){
		dfs2(d+1, m+a[d], l, 0, 0);
		dfs2(d+1, m, l, 1, 0);
		dfs2(d+1, m-c[d], l+b[d], 0, 1);
		return;
	}
	if(p == 0){
		dfs2(d+1, m+a[d], l, 0, s);
		dfs2(d+1, m, l, 1, s);
	}
	else dfs2(d+1, m-c[d], l+b[d], 0, s);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}
	
	dfs(1, 0, 0, 0);
	dfs2(n/2+1, 0, 0, 0, 0);
	
	sort(vec2[0].begin(), vec2[0].end());
	sort(vec2[1].begin(), vec2[1].end());
	
	for(int i = 0; i < 2; i++){
		maxvec[i].resize(vec2[i].size());
		llint mx = -inf;
		for(int j = (int)vec2[i].size()-1; j >= 0; j--){
			mx = max(mx, vec2[i][j].second);
			maxvec[i][j] = mx;
		}
	}
	
	llint ans = 0;
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < (int)vec[i].size(); j++){
			llint m = vec[i][j].first, l = vec[i][j].second;
			llint p = lower_bound(vec2[i].begin(), vec2[i].end(), P(-m, -inf)) - vec2[i].begin();
			if(p >= (int)vec2[i].size()) continue;
			ans = max(ans, l + maxvec[i][p]);
		}
	}
	cout << ans << endl;
	
	return 0;
}
0