結果

問題 No.974 最後の日までに
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-07-27 16:16:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 202,752 KB
実行使用メモリ 10,316 KB
最終ジャッジ日時 2024-04-15 03:34:43
合計ジャッジ時間 5,861 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
9,924 KB
testcase_01 AC 73 ms
10,184 KB
testcase_02 AC 67 ms
10,316 KB
testcase_03 AC 60 ms
9,420 KB
testcase_04 AC 62 ms
9,416 KB
testcase_05 AC 69 ms
10,188 KB
testcase_06 AC 71 ms
9,924 KB
testcase_07 AC 65 ms
9,032 KB
testcase_08 AC 61 ms
8,900 KB
testcase_09 AC 68 ms
9,160 KB
testcase_10 AC 64 ms
9,164 KB
testcase_11 AC 60 ms
9,548 KB
testcase_12 AC 60 ms
9,288 KB
testcase_13 AC 66 ms
9,676 KB
testcase_14 AC 64 ms
9,932 KB
testcase_15 AC 62 ms
9,416 KB
testcase_16 AC 63 ms
9,928 KB
testcase_17 AC 55 ms
10,060 KB
testcase_18 AC 53 ms
9,032 KB
testcase_19 AC 53 ms
9,292 KB
testcase_20 AC 54 ms
9,548 KB
testcase_21 AC 53 ms
8,900 KB
testcase_22 AC 54 ms
9,548 KB
testcase_23 AC 54 ms
9,416 KB
testcase_24 AC 54 ms
8,776 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 68 ms
7,116 KB
testcase_28 AC 77 ms
10,184 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 76 ms
8,772 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 50 ms
7,112 KB
testcase_34 AC 91 ms
9,540 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 84 ms
9,676 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,948 KB
testcase_40 AC 37 ms
7,116 KB
testcase_41 AC 49 ms
9,032 KB
testcase_42 AC 87 ms
8,908 KB
testcase_43 AC 88 ms
10,052 KB
testcase_44 AC 68 ms
7,112 KB
testcase_45 AC 55 ms
7,116 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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() {
    assert(w <= 26);
    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;
}
0