結果

問題 No.974 最後の日までに
ユーザー KeiKei
提出日時 2024-02-27 18:32:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,546 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 94,468 KB
実行使用メモリ 28,160 KB
最終ジャッジ日時 2024-02-27 18:32:58
合計ジャッジ時間 13,543 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 343 ms
28,160 KB
testcase_01 AC 445 ms
28,160 KB
testcase_02 AC 401 ms
28,160 KB
testcase_03 AC 393 ms
28,160 KB
testcase_04 AC 431 ms
28,160 KB
testcase_05 AC 401 ms
28,160 KB
testcase_06 AC 413 ms
28,160 KB
testcase_07 AC 431 ms
28,160 KB
testcase_08 AC 391 ms
28,160 KB
testcase_09 AC 412 ms
28,160 KB
testcase_10 AC 439 ms
28,160 KB
testcase_11 AC 431 ms
28,160 KB
testcase_12 AC 424 ms
28,160 KB
testcase_13 AC 441 ms
28,160 KB
testcase_14 AC 417 ms
28,160 KB
testcase_15 AC 426 ms
28,160 KB
testcase_16 AC 452 ms
28,160 KB
testcase_17 AC 24 ms
6,676 KB
testcase_18 AC 22 ms
6,676 KB
testcase_19 AC 21 ms
6,676 KB
testcase_20 AC 25 ms
6,676 KB
testcase_21 AC 25 ms
6,676 KB
testcase_22 AC 24 ms
6,676 KB
testcase_23 AC 23 ms
6,676 KB
testcase_24 AC 23 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 316 ms
18,816 KB
testcase_28 AC 482 ms
28,160 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 57 ms
6,676 KB
testcase_31 RE -
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 273 ms
18,816 KB
testcase_34 AC 602 ms
28,160 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 91 ms
6,676 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 21 ms
6,676 KB
testcase_41 AC 25 ms
6,676 KB
testcase_42 AC 108 ms
6,676 KB
testcase_43 AC 105 ms
6,676 KB
testcase_44 AC 76 ms
6,676 KB
testcase_45 AC 65 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 = 1LL << 62;
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;
  map<long long, long long> m2;
	auto dfs2 = [&](auto dfs2, long long love, long long money, int l, int r) -> void {
		if (l == r) {
			long long tmp = m2.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);
    m2[itr->first] = max(itr->second, tmp);
    tmp = max(tmp, m[itr->first]);
  }
	dfs2(dfs2, 0LL, 0LL, mid, W);
  m.clear();
  m2.clear();
  tmp = -INF;
  dfs1(dfs1, 0LL, 0LL, 0, mid - 1);
  m[INF] = -INF;
  itr = m.end();
  while (itr != m.begin()) {
    itr = prev(itr);
    m2[itr->first] = max(itr->second, tmp);
    tmp = max(tmp, m[itr->first]);
  }
	dfs2(dfs2, 0LL, 0LL, mid - 1, W);
  cout << ans << endl;
}
0