結果
問題 | No.974 最後の日までに |
ユーザー | Kei |
提出日時 | 2024-02-27 18:34:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 475 ms / 2,000 ms |
コード長 | 1,603 bytes |
コンパイル時間 | 1,065 ms |
コンパイル使用メモリ | 94,596 KB |
実行使用メモリ | 28,160 KB |
最終ジャッジ日時 | 2024-02-27 18:34:50 |
合計ジャッジ時間 | 11,871 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 324 ms
28,160 KB |
testcase_01 | AC | 400 ms
28,160 KB |
testcase_02 | AC | 363 ms
28,160 KB |
testcase_03 | AC | 371 ms
28,160 KB |
testcase_04 | AC | 366 ms
28,160 KB |
testcase_05 | AC | 394 ms
28,160 KB |
testcase_06 | AC | 371 ms
28,160 KB |
testcase_07 | AC | 377 ms
28,160 KB |
testcase_08 | AC | 395 ms
28,160 KB |
testcase_09 | AC | 384 ms
28,160 KB |
testcase_10 | AC | 395 ms
28,160 KB |
testcase_11 | AC | 428 ms
28,160 KB |
testcase_12 | AC | 395 ms
28,160 KB |
testcase_13 | AC | 378 ms
28,160 KB |
testcase_14 | AC | 404 ms
28,160 KB |
testcase_15 | AC | 390 ms
28,160 KB |
testcase_16 | AC | 397 ms
28,160 KB |
testcase_17 | AC | 24 ms
6,676 KB |
testcase_18 | AC | 22 ms
6,676 KB |
testcase_19 | AC | 22 ms
6,676 KB |
testcase_20 | AC | 26 ms
6,676 KB |
testcase_21 | AC | 25 ms
6,676 KB |
testcase_22 | AC | 23 ms
6,676 KB |
testcase_23 | AC | 24 ms
6,676 KB |
testcase_24 | AC | 24 ms
6,676 KB |
testcase_25 | AC | 3 ms
6,676 KB |
testcase_26 | AC | 2 ms
6,676 KB |
testcase_27 | AC | 292 ms
18,816 KB |
testcase_28 | AC | 437 ms
28,160 KB |
testcase_29 | AC | 2 ms
6,676 KB |
testcase_30 | AC | 56 ms
6,676 KB |
testcase_31 | AC | 2 ms
6,676 KB |
testcase_32 | AC | 2 ms
6,676 KB |
testcase_33 | AC | 270 ms
18,816 KB |
testcase_34 | AC | 475 ms
28,160 KB |
testcase_35 | AC | 2 ms
6,676 KB |
testcase_36 | AC | 2 ms
6,676 KB |
testcase_37 | AC | 90 ms
6,676 KB |
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 | 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 | 63 ms
6,676 KB |
testcase_46 | AC | 2 ms
6,676 KB |
testcase_47 | AC | 1 ms
6,676 KB |
testcase_48 | AC | 2 ms
6,676 KB |
testcase_49 | AC | 1 ms
6,676 KB |
testcase_50 | AC | 2 ms
6,676 KB |
testcase_51 | AC | 2 ms
6,676 KB |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<map> using namespace std; long long INF = 1LL << 61; int main() { int W; cin >> W; if (W == 1) { cout << 0 << endl; return 0; } 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; }