結果

問題 No.974 最後の日までに
ユーザー KeiKei
提出日時 2024-02-27 19:11:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,209 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 214,116 KB
実行使用メモリ 8,144 KB
最終ジャッジ日時 2024-02-27 19:12:00
合計ジャッジ時間 5,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
8,144 KB
testcase_01 AC 46 ms
8,144 KB
testcase_02 AC 41 ms
8,144 KB
testcase_03 AC 41 ms
8,144 KB
testcase_04 AC 43 ms
8,144 KB
testcase_05 AC 46 ms
8,144 KB
testcase_06 AC 46 ms
8,144 KB
testcase_07 AC 43 ms
8,144 KB
testcase_08 AC 41 ms
8,144 KB
testcase_09 AC 42 ms
8,144 KB
testcase_10 AC 41 ms
8,144 KB
testcase_11 AC 40 ms
8,144 KB
testcase_12 AC 39 ms
8,144 KB
testcase_13 AC 42 ms
8,144 KB
testcase_14 AC 43 ms
8,144 KB
testcase_15 AC 40 ms
8,144 KB
testcase_16 WA -
testcase_17 AC 36 ms
8,144 KB
testcase_18 AC 37 ms
8,144 KB
testcase_19 AC 36 ms
8,144 KB
testcase_20 AC 36 ms
8,144 KB
testcase_21 AC 37 ms
8,144 KB
testcase_22 AC 38 ms
8,144 KB
testcase_23 WA -
testcase_24 AC 36 ms
8,144 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 47 ms
8,144 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 45 ms
8,144 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 32 ms
6,548 KB
testcase_34 AC 56 ms
8,144 KB
testcase_35 AC 1 ms
6,548 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
6,548 KB
testcase_39 AC 2 ms
6,548 KB
testcase_40 AC 23 ms
6,548 KB
testcase_41 AC 31 ms
8,144 KB
testcase_42 WA -
testcase_43 AC 53 ms
8,144 KB
testcase_44 WA -
testcase_45 AC 32 ms
6,548 KB
testcase_46 AC 2 ms
6,548 KB
testcase_47 AC 2 ms
6,548 KB
testcase_48 AC 2 ms
6,548 KB
testcase_49 AC 2 ms
6,548 KB
testcase_50 AC 2 ms
6,548 KB
testcase_51 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int main() {
	int W;
	cin >> W;
	vector<long long> a(W), b(W), c(W);
	for (int i = 0; i < W; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vector<pair<long long, long long>> A;//(money, love)
	long long ans = 0;
	auto dfs1 = [&](auto dfs1, long long love, long long money, int l, int r) -> void {
		if (l == r) {
			A.push_back(make_pair(money, love));
			return;
		}
		dfs1(dfs1, love, money + a[l], l + 1, r);
		if (l + 2 <= r) {
			dfs1(dfs1, love + b[l + 1], money - c[l + 1], l + 2, r);
		}
		};
	auto dfs2 = [&](auto dfs2, long long love, long long money, int l, int r) -> void {
		if (l == r) {
			long long tmp = lower_bound(A.begin(), A.end(), make_pair(-money, 0LL))->second;
			ans = max(ans, tmp + love);
			return;
		}
		dfs2(dfs2, love, money + a[l], l + 1, r);
		if (l + 2 <= r) {
			dfs2(dfs2, love + b[l + 1], money - c[l + 1], l + 2, r);
		}
		};
	int mid = W / 2;
	dfs1(dfs1, 0LL, 0LL, 0, mid);
	A.push_back(make_pair(INF, -INF));
	sort(A.begin(), A.end());
	int N = A.size();
	for (int i = N - 2; i >= 0; i--) {
		A[i].second = max(A[i].second, A[i + 1].second);
	}
	dfs2(dfs2, 0LL, 0LL, mid, W);
	cout << ans << endl;
}
0