結果
問題 |
No.974 最後の日までに
|
ユーザー |
![]() |
提出日時 | 2023-07-27 15:57:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 2,366 ms |
コンパイル使用メモリ | 201,348 KB |
最終ジャッジ日時 | 2025-02-15 19:32:47 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = long long; using pii = pair<i64, i64>; i64 w, mid, a[55], b[55], c[55]; i64 maxl = 0; vector<pii> ans[55]; void dfs1(int l, int r, i64 x, i64 y) { if(l >= r) { ans[l].push_back({x, y}); return; } dfs1(l + 1, r, x + a[l], y); dfs1(l + 2, r, x - c[l + 1], y + b[l + 1]); } void dfs2(int r, i64 x, i64 y) { if(r < mid - 1) return; if(ans[r + 1].size()) { maxl = max(maxl, lower_bound(ans[r + 1].begin(), ans[r + 1].end(), pii{-x, 0})->second + y); } dfs2(r - 1, x + a[r], y); dfs2(r - 2, x - c[r], y + b[r]); } int main() { cin >> w; for(int i = 0; i < w; i ++) cin >> a[i] >> b[i] >> c[i]; mid = w / 2; dfs1(0, mid, 0, 0); for(auto t : {mid, mid + 1}) { sort(ans[t].begin(), ans[t].end()); ans[t].push_back({1e18, -1e18}); for(int i = (int)ans[t].size() - 2; i >= 0; i --) ans[t][i].second = max(ans[t][i].second, ans[t][i + 1].second); } dfs2(w - 1, 0, 0); cout << maxl; }