結果

問題 No.974 最後の日までに
ユーザー betrue12betrue12
提出日時 2020-01-17 23:41:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,685 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 208,044 KB
実行使用メモリ 16,816 KB
最終ジャッジ日時 2024-04-14 21:51:18
合計ジャッジ時間 8,829 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
16,152 KB
testcase_01 AC 133 ms
16,664 KB
testcase_02 AC 127 ms
16,412 KB
testcase_03 AC 118 ms
16,112 KB
testcase_04 AC 124 ms
16,300 KB
testcase_05 AC 126 ms
16,816 KB
testcase_06 AC 130 ms
16,712 KB
testcase_07 AC 126 ms
15,716 KB
testcase_08 AC 122 ms
16,704 KB
testcase_09 AC 132 ms
16,272 KB
testcase_10 AC 128 ms
16,268 KB
testcase_11 AC 138 ms
16,284 KB
testcase_12 AC 135 ms
16,248 KB
testcase_13 AC 136 ms
15,936 KB
testcase_14 AC 126 ms
16,056 KB
testcase_15 AC 128 ms
15,880 KB
testcase_16 AC 129 ms
16,084 KB
testcase_17 AC 145 ms
16,292 KB
testcase_18 AC 146 ms
16,740 KB
testcase_19 AC 139 ms
15,872 KB
testcase_20 AC 144 ms
16,308 KB
testcase_21 AC 146 ms
15,880 KB
testcase_22 AC 141 ms
15,716 KB
testcase_23 AC 140 ms
16,272 KB
testcase_24 AC 144 ms
15,672 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 99 ms
10,316 KB
testcase_28 AC 135 ms
16,708 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 152 ms
15,896 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 83 ms
9,804 KB
testcase_34 AC 136 ms
15,872 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 147 ms
15,732 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 91 ms
10,436 KB
testcase_41 AC 121 ms
16,452 KB
testcase_42 AC 145 ms
15,856 KB
testcase_43 AC 144 ms
16,552 KB
testcase_44 AC 108 ms
10,828 KB
testcase_45 AC 96 ms
10,824 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int W;
    cin >> W;
    vector<int64_t> A(W), B(W), C(W);
    for(int i=0; i<W; i++) cin >> A[i] >> B[i] >> C[i];

    auto calculate_cand = [&](int H, int offset){
        vector<pair<int64_t, int64_t>> res;
        res.emplace_back(0, 0);
        for(int d=0; 2*d<=H; d++){
            vector<int> order;
            for(int i=0; i<H-2*d; i++) order.push_back(0);
            for(int i=0; i<d; i++) order.push_back(1);
            do{
                int64_t money = 0, love = 0;
                int pt = offset;
                for(int t : order){
                    if(t){
                        money -= C[pt+1];
                        love += B[pt+1];
                        pt += 2;
                    }else{
                        money += A[pt];
                        pt += 1;
                    }
                }
                res.emplace_back(money, love);
            }while(next_permutation(order.begin(), order.end()));
        }
        sort(res.begin(), res.end());
        return res;
    };

    int H = W/2;
    int H2 = W-H;
    int64_t ans = 0;
    for(int k=0; k<2; k++){
        auto res1 = calculate_cand(H, 0);
        auto res2 = calculate_cand(H2, H);
        int sz = res2.size();
        int pt = sz-1;
        int64_t mx = -1e18;
        for(auto& p : res1){
            int64_t money = p.first, love = p.second;
            while(pt >= 0 && money + res2[pt].first >= 0){
                mx = max(mx, res2[pt].second);
                pt--;
            }
            ans = max(ans, love + mx);
        }
        H++;
        H2--;
    }
    cout << ans << endl;
    return 0;
}
0