結果

問題 No.974 最後の日までに
ユーザー milanis48663220milanis48663220
提出日時 2020-06-11 00:41:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 661 ms / 2,000 ms
コード長 2,690 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 94,116 KB
実行使用メモリ 30,972 KB
最終ジャッジ日時 2023-09-06 01:53:52
合計ジャッジ時間 16,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 578 ms
30,952 KB
testcase_01 AC 538 ms
30,840 KB
testcase_02 AC 536 ms
30,916 KB
testcase_03 AC 509 ms
30,860 KB
testcase_04 AC 519 ms
30,808 KB
testcase_05 AC 528 ms
30,912 KB
testcase_06 AC 523 ms
30,952 KB
testcase_07 AC 517 ms
30,888 KB
testcase_08 AC 516 ms
30,812 KB
testcase_09 AC 526 ms
30,968 KB
testcase_10 AC 547 ms
30,952 KB
testcase_11 AC 545 ms
30,972 KB
testcase_12 AC 546 ms
30,944 KB
testcase_13 AC 521 ms
30,836 KB
testcase_14 AC 521 ms
30,860 KB
testcase_15 AC 542 ms
30,856 KB
testcase_16 AC 543 ms
30,852 KB
testcase_17 AC 98 ms
4,376 KB
testcase_18 AC 100 ms
4,384 KB
testcase_19 AC 97 ms
4,380 KB
testcase_20 AC 101 ms
4,380 KB
testcase_21 AC 101 ms
4,376 KB
testcase_22 AC 98 ms
4,376 KB
testcase_23 AC 99 ms
4,376 KB
testcase_24 AC 99 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 446 ms
23,316 KB
testcase_28 AC 634 ms
30,948 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 143 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 361 ms
20,468 KB
testcase_34 AC 661 ms
30,896 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 204 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 78 ms
4,376 KB
testcase_41 AC 100 ms
4,380 KB
testcase_42 AC 224 ms
4,380 KB
testcase_43 AC 229 ms
4,376 KB
testcase_44 AC 164 ms
4,380 KB
testcase_45 AC 139 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int W;
int M;
ll a[52], b[52], c[52];
map<ll, ll> mpl, mpr;

vector<int> buf;
bool left_half;

void dfs(int c1, int c2){
    if(c1 == 0 && c2 == 0){
        int cur = (left_half ? 0 : M);
        ll money = 0, likes = 0;
        for(int i : buf) {
            if(i == 1){
                money += a[cur];
            }else{
                likes += b[cur+1];
                money -= c[cur+1];
            }
            cur += i;
        }
        if(left_half) {
            if(mpl.count(money) > 0){
                mpl[money] = max(mpl[money], likes);
            }else{
                mpl[money] = likes;
            }
        }else{
            if(mpr.count(money) > 0){
                mpr[money] = max(mpr[money], likes);
            }else{
                mpr[money] = likes;
            }
        }
    }
    if(c1 != 0){
        buf.push_back(1);
        dfs(c1-1, c2);
        buf.pop_back();
    }
    if(c2 != 0){
        buf.push_back(2);
        dfs(c1, c2-1);
        buf.pop_back();
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> W;
    for(int i = 0; i < W; i++) cin >> a[i] >> b[i] >> c[i];
    if(W == 1){
        cout << 0 << endl;
        return 0;
    }
    M = W/2;
    left_half = true;
    for(int i = 0; 2*i <= M; i++){
        dfs(M-2*i, i);
    }
    left_half = false;
    for(int i = 0; 2*i <= W-M; i++){
        dfs(W-M-2*i, i);
    }
    auto p = mpr.end();
    ll cur_max = 0;
    while(true){
        p--;
        cur_max = max(cur_max, p->second);
        mpr[p->first] = cur_max;
        if(p == mpr.begin()) break;
    }
    ll ans = 0;
    for(auto i : mpl){
        ll money = i.first;
        ll likes = i.second;
        auto p = mpr.lower_bound(-money);
        if(p == mpr.end()) continue;
        ans = max(ans, likes+p->second);
    }

    // 境目でデートする
    M++;
    mpl.clear(); mpr.clear();
    left_half = true;
    for(int i = 0; 2*i <= M; i++){
        dfs(M-2*i, i);
    }
    left_half = false;
    for(int i = 0; 2*i <= W-M; i++){
        dfs(W-M-2*i, i);
    }
    p = mpr.end();
    cur_max = 0;
    while(true){
        p--;
        cur_max = max(cur_max, p->second);
        mpr[p->first] = cur_max;
        if(p == mpr.begin()) break;
    }
    for(auto i : mpl){
        ll money = i.first;
        ll likes = i.second;
        auto p = mpr.lower_bound(-money);
        if(p == mpr.end()) continue;
        ans = max(ans, likes+p->second);
    }
    cout << ans << endl;
} 
0