結果

問題 No.974 最後の日までに
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-07-27 15:57:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 2,733 ms
コンパイル使用メモリ 204,216 KB
実行使用メモリ 10,444 KB
最終ジャッジ日時 2024-04-15 03:20:06
合計ジャッジ時間 6,252 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
9,292 KB
testcase_01 AC 77 ms
9,284 KB
testcase_02 AC 72 ms
8,900 KB
testcase_03 AC 66 ms
9,668 KB
testcase_04 AC 70 ms
10,312 KB
testcase_05 AC 77 ms
9,672 KB
testcase_06 AC 77 ms
8,900 KB
testcase_07 AC 69 ms
10,060 KB
testcase_08 AC 66 ms
8,776 KB
testcase_09 AC 70 ms
9,284 KB
testcase_10 AC 70 ms
9,800 KB
testcase_11 AC 68 ms
9,028 KB
testcase_12 AC 66 ms
8,904 KB
testcase_13 AC 71 ms
8,900 KB
testcase_14 AC 71 ms
10,056 KB
testcase_15 AC 66 ms
9,284 KB
testcase_16 AC 67 ms
10,060 KB
testcase_17 AC 58 ms
9,284 KB
testcase_18 AC 57 ms
9,032 KB
testcase_19 AC 59 ms
10,184 KB
testcase_20 AC 57 ms
10,440 KB
testcase_21 AC 57 ms
10,444 KB
testcase_22 AC 57 ms
9,032 KB
testcase_23 AC 58 ms
9,544 KB
testcase_24 AC 58 ms
10,184 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 72 ms
7,112 KB
testcase_28 AC 83 ms
8,900 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 81 ms
9,804 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 53 ms
7,120 KB
testcase_34 AC 96 ms
10,312 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 88 ms
8,904 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 38 ms
7,112 KB
testcase_41 AC 51 ms
9,288 KB
testcase_42 AC 89 ms
9,544 KB
testcase_43 AC 90 ms
9,164 KB
testcase_44 AC 72 ms
7,112 KB
testcase_45 AC 57 ms
7,048 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,944 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() {
    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