結果

問題 No.974 最後の日までに
ユーザー KeiKei
提出日時 2024-02-27 17:47:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 115,388 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-02-27 17:47:58
合計ジャッジ時間 6,682 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
15,872 KB
testcase_01 AC 156 ms
15,872 KB
testcase_02 AC 148 ms
15,872 KB
testcase_03 AC 151 ms
15,872 KB
testcase_04 AC 158 ms
15,872 KB
testcase_05 AC 185 ms
15,872 KB
testcase_06 AC 172 ms
15,872 KB
testcase_07 AC 164 ms
15,872 KB
testcase_08 AC 150 ms
15,872 KB
testcase_09 AC 154 ms
15,872 KB
testcase_10 AC 154 ms
15,872 KB
testcase_11 AC 157 ms
15,872 KB
testcase_12 AC 177 ms
15,872 KB
testcase_13 AC 161 ms
15,872 KB
testcase_14 AC 159 ms
15,872 KB
testcase_15 AC 163 ms
15,872 KB
testcase_16 WA -
testcase_17 AC 13 ms
6,676 KB
testcase_18 AC 12 ms
6,676 KB
testcase_19 AC 12 ms
6,676 KB
testcase_20 AC 14 ms
6,676 KB
testcase_21 AC 14 ms
6,676 KB
testcase_22 AC 13 ms
6,676 KB
testcase_23 WA -
testcase_24 AC 13 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 206 ms
15,872 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 30 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 106 ms
11,136 KB
testcase_34 AC 209 ms
15,872 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 1 ms
6,676 KB
testcase_40 AC 11 ms
6,676 KB
testcase_41 AC 13 ms
6,676 KB
testcase_42 WA -
testcase_43 AC 54 ms
6,676 KB
testcase_44 WA -
testcase_45 AC 32 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 2 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 2 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>
#include<map>
using namespace std;
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];
	}
  map<long long, long long> m;//m[money] = love
	auto dfs1 = [&](auto dfs1, long long love, long long money, int l, int r) -> void {
		if (l == r) {
			m[money] = max(m[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);
		}
		};
	long long ans = 0;
	auto dfs2 = [&](auto dfs2, long long love, long long money, int l, int r) -> void {
		if (l == r) {
			long long tmp = m.lower_bound(-money)->second + love;
			ans = max(ans, tmp);
			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);
  m[INF] = -INF;
  auto itr = m.end();
  long long tmp = -INF;
  while (itr != m.begin()) {
    itr = prev(itr);
    m[itr->first] = max(itr->second, tmp);
    tmp = max(tmp, m[itr->first]);
  }
	dfs2(dfs2, 0LL, 0LL, mid, W);
	cout << ans << endl;
}
0