結果

問題 No.974 最後の日までに
ユーザー nebukuro09nebukuro09
提出日時 2020-01-17 23:37:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,659 bytes
コンパイル時間 1,718 ms
コンパイル使用メモリ 174,224 KB
実行使用メモリ 13,288 KB
最終ジャッジ日時 2023-09-08 08:11:18
合計ジャッジ時間 27,945 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 661 ms
11,212 KB
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 AC 653 ms
11,464 KB
testcase_16 AC 653 ms
11,820 KB
testcase_17 AC 673 ms
11,736 KB
testcase_18 AC 672 ms
12,136 KB
testcase_19 AC 671 ms
11,644 KB
testcase_20 AC 672 ms
12,380 KB
testcase_21 AC 672 ms
11,408 KB
testcase_22 AC 669 ms
11,356 KB
testcase_23 AC 670 ms
11,668 KB
testcase_24 AC 668 ms
11,608 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 477 ms
7,648 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 679 ms
11,732 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 463 ms
8,100 KB
testcase_41 AC 651 ms
11,288 KB
testcase_42 AC 678 ms
12,992 KB
testcase_43 AC 675 ms
12,596 KB
testcase_44 AC 481 ms
8,972 KB
testcase_45 AC 360 ms
8,360 KB
testcase_46 WA -
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;

int N;
ll s;
ll A[55];
ll B[55];
ll C[55];

ll solve(int M1, int M2) {
    vector<pair<ll, ll>> v;

    REP(mask, 1 << M1) {
        if (mask & (mask << 1)) continue;
        if (mask & (1 << (M1 - 1))) continue;
        ll b = 0;
        ll a = 0;
        REP(i, M1) if (mask & (1 << i)) b += B[i+1], a += A[i+1] + A[i] + C[i+1];
        v.push_back({a, b});
    }

    sort(v.rbegin(), v.rend());
    //REP(i, v.size()) v[i].first *= -1;
    for (int i = (int)v.size()-2; i >= 0; --i) v[i].second = max(v[i].second, v[i+1].second);

    ll ans = 0;

    REP(mask, 1 << M2) {
        if (mask & (mask << 1)) continue;
        if (mask & (1 << (M2 - 1))) continue;
        ll b = 0;
        ll a = 0;
        REP(i, M2) if (mask & (1 << i)) b += B[M1+i+1], a += A[M1+i+1] + A[M1+i] + C[M1+i+1];
        int hi = (int)v.size();
        int lo = -1;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if (v[mid].first + a > s) lo = mid;
            else hi = mid;
        }
        ans = max(ans, hi == v.size() ? 0L : v[hi].second + b);
    }

    return ans;
}

void solve() {
    cin >> N;
    REP(i, N) cin >> A[i] >> B[i] >> C[i];
    s = 0;
    REP(i, N) s += A[i];

    if (N <= 2) {
        cout << 0 << endl;
        return;
    }

    ll ans = max(solve(N / 2, N / 2 % 2), solve(N / 2 + 1, N / 2 % 2 - 1));
    ans = max(ans, solve(N / 2 - 1, N / 2 + N % 2 + 1));
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0