結果

問題 No.974 最後の日までに
ユーザー KeiKei
提出日時 2024-02-27 16:50:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,157 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 86,532 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-27 16:50:52
合計ジャッジ時間 4,474 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int INF = 1e9;
int main() {
	int W;
	cin >> W;
	vector<int> a(W), b(W), c(W);
	for (int i = 0; i < W; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vector<pair<int, int>> A;//(money, love)
	int ans = 0;
	auto dfs1 = [&](auto dfs1, int love, int money, int l, int r) -> void {
		if (l == r) {
			A.emplace_back(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, int love, int money, int l, int r) -> void {
		if (l == r) {
			int tmp = lower_bound(A.begin(), A.end(), make_pair(-money, 0))->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, 0, 0, 0, mid);
	A.emplace_back(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, 0, 0, mid, W);
	cout << ans << endl;
}
0