結果

問題 No.974 最後の日までに
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-07-27 15:51:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,057 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 203,756 KB
実行使用メモリ 10,828 KB
最終ジャッジ日時 2024-04-15 03:14:26
合計ジャッジ時間 5,050 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 27 ms
9,292 KB
testcase_18 AC 27 ms
9,160 KB
testcase_19 AC 27 ms
9,668 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
6,940 KB
testcase_30 WA -
testcase_31 RE -
testcase_32 AC 2 ms
6,940 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 73 ms
10,568 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 32 ms
7,116 KB
testcase_41 AC 46 ms
9,164 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

using pii = pair<i64, i64>;

int w, 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 - 1].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(ans[r].size()) {
        maxl = max(maxl, lower_bound(ans[r].begin(), ans[r].end(), pii{-x, 0})->second + y);
        return;
    }
    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];
    
    int 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