結果

問題 No.974 最後の日までに
ユーザー betrue12betrue12
提出日時 2020-01-17 23:56:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 1,621 bytes
コンパイル時間 2,732 ms
コンパイル使用メモリ 209,944 KB
実行使用メモリ 17,308 KB
最終ジャッジ日時 2023-07-27 09:08:07
合計ジャッジ時間 10,521 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
15,488 KB
testcase_01 AC 153 ms
17,080 KB
testcase_02 AC 151 ms
16,252 KB
testcase_03 AC 148 ms
15,968 KB
testcase_04 AC 150 ms
16,900 KB
testcase_05 AC 154 ms
16,332 KB
testcase_06 AC 151 ms
16,492 KB
testcase_07 AC 148 ms
16,308 KB
testcase_08 AC 147 ms
15,780 KB
testcase_09 AC 150 ms
15,560 KB
testcase_10 AC 147 ms
17,308 KB
testcase_11 AC 152 ms
15,560 KB
testcase_12 AC 152 ms
16,080 KB
testcase_13 AC 150 ms
15,844 KB
testcase_14 AC 149 ms
16,312 KB
testcase_15 AC 154 ms
16,072 KB
testcase_16 AC 152 ms
15,744 KB
testcase_17 AC 165 ms
15,844 KB
testcase_18 AC 170 ms
16,356 KB
testcase_19 AC 169 ms
16,136 KB
testcase_20 AC 170 ms
16,732 KB
testcase_21 AC 172 ms
16,152 KB
testcase_22 AC 171 ms
15,576 KB
testcase_23 AC 171 ms
16,356 KB
testcase_24 AC 170 ms
15,488 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 117 ms
11,064 KB
testcase_28 AC 159 ms
15,612 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 174 ms
15,780 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 99 ms
9,424 KB
testcase_34 AC 161 ms
15,968 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 177 ms
17,180 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 109 ms
10,628 KB
testcase_41 AC 144 ms
16,416 KB
testcase_42 AC 172 ms
15,624 KB
testcase_43 AC 173 ms
15,848 KB
testcase_44 AC 130 ms
10,044 KB
testcase_45 AC 106 ms
9,888 KB
testcase_46 AC 2 ms
4,384 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,384 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 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;
        for(int d=0; 2*d<=H; d++){
            vector<int> steps;
            for(int i=0; i<H-2*d; i++) steps.push_back(1);
            for(int i=0; i<d; i++) steps.push_back(2);
            do{
                int64_t money = 0, love = 0;
                int pt = offset;
                for(int s : steps){
                    if(s == 1){
                        money += A[pt];
                    }else{
                        money -= C[pt+1];
                        love += B[pt+1];
                    }
                    pt += s;
                }
                res.emplace_back(money, love);
            }while(next_permutation(steps.begin(), steps.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