結果

問題 No.974 最後の日までに
ユーザー parukiparuki
提出日時 2020-01-25 17:37:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,724 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 182,532 KB
実行使用メモリ 38,864 KB
最終ジャッジ日時 2023-10-12 04:39:48
合計ジャッジ時間 24,594 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 573 ms
36,556 KB
testcase_18 AC 577 ms
36,624 KB
testcase_19 AC 582 ms
36,652 KB
testcase_20 AC 579 ms
36,572 KB
testcase_21 AC 580 ms
36,520 KB
testcase_22 AC 578 ms
36,636 KB
testcase_23 AC 575 ms
36,644 KB
testcase_24 AC 577 ms
36,536 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,352 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 1 ms
4,352 KB
testcase_48 WA -
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

struct P{ ll a,b,c; };

void solve() {
    int W;
    cin >> W;
    if (W == 1) {
        cout << 0 << endl;
        return;
    }

    vll A(W), B(W), C(W);
    rep(i, W) {
        cin >> A[i] >> B[i] >> C[i];
    }

    auto g = [&](vector<P> p) {
        vi S{ 0 };
        for (int i = 1; i < sz(p); ++i) {
            int n = sz(S);
            rep(j, n) {
                int U = S[j];
                if (!(U >> j & (i - 1))) {
                    S.push_back(U | 1 << i);
                }
            }
        }

        int n = sz(S);
        // (money, likes)
        vector<pair<ll, ll> > res(n);
        rep(i, n) {
            int U = S[i];
            if (sz(p) > 0) {
                res[i].first += p[0].a;
            }
            for (int j = 1; j < sz(p); ++j) {
                if (U >> j & 1) {
                    // 前回はアルバイトができなかった
                    res[i].first -= p[j - 1].a + p[j].c;
                    res[i].second += p[j].b;
                } else {
                    res[i].first += p[j].a;
                }
            }
        }

        sort(all(res));
        // (money, likes)
        vector<pair<ll, ll> > so;
        each(r, res) {
            while (sz(so) && so.back().second <= r.second) {
                so.pop_back();
            }
            so.push_back(r);
        }
        return so;
    };

    ll ans = 0;

    auto f = [&](int n) {
        // [0, n), [n, W)
        vector<P> pre, pos;
        rep(i, n) {
            pre.push_back(P{ A[i],B[i],C[i] });
        }
        FOR(i, n, W) {
            pos.push_back(P{ A[i],B[i],C[i] });
        }

        auto L = g(pre);
        auto R = g(pos);
        each(le, L) {
            auto itri = lower_bound(all(R), pair<ll, ll>(-le.first, 0));
            if (itri == R.end()) {
                continue;
            }
            assert(le.first + itri->first >= 0);
            smax(ans, le.second + itri->second);
        }
    };

    f(W / 2);
    f(W / 2 - 1);
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0