結果

問題 No.974 最後の日までに
ユーザー 沙耶花沙耶花
提出日時 2019-12-11 14:08:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,833 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 212,448 KB
実行使用メモリ 34,368 KB
最終ジャッジ日時 2023-09-07 23:25:39
合計ジャッジ時間 81,606 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1,644 ms
20,448 KB
testcase_28 TLE -
testcase_29 AC 1 ms
4,380 KB
testcase_30 TLE -
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1,111 ms
17,596 KB
testcase_34 TLE -
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 TLE -
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1,563 ms
21,684 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 AC 1,618 ms
21,436 KB
testcase_45 AC 1,111 ms
17,924 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

using i64 = long long;


signed main(){
    int n;
    cin >> n;
    vector<i64> a(n), b(n), c(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i] >> b[i] >> c[i];

    array<int, 2> m{n / 2, (n + 1) / 2};


    // v[k][flag] = (money, val)
    vector<vector<pair<i64,i64>>> v(2);
    vector<vector<pair<i64,i64>>> special(2);

    for(int k = 0; k < 2; ++k){
        for(int i = 0; i < (1 << m[k]); ++i){
            i64 money = 0;
            i64 val = 0;
            bool flag = false;
            bool ignore = false;
            for(int j = 0; j < m[k]; ++j){
                if((i >> j) & 1){
                    if(flag){
                        ignore = true;
                        break;
                    }
                    flag = true;
                }
                else{
                    if(flag){
                        val += b[j + m[0] * k];
                        money -= c[j + m[0] * k];
                    }
                    else{
                        money += a[j + m[0] * k];
                    }
                    flag = false;
                }
            }
            if(!ignore){
                v[k].emplace_back(money, val);
                if(!k && flag)
                    special[k].emplace_back(money, val);
                if(k && !(i & 1))
                    special[k].emplace_back(money - a[m[0]] - c[m[0]], val + b[m[0]]);
            }
        }
    }

    sort(v[1].begin(),v[1].end());
	sort(special[1].begin(),special[1].end());
	
	long long last = 0;
	for(auto it = v[1].rbegin();it!=v[1].rend();it++){
		last = max(last,(*it).second);
		(*it).second = last;
	}
	
	last=0;
	for(auto it = special[1].rbegin();it!=special[1].rend();it++){
		last = max(last,(*it).second);
		(*it).second = last;
	}

	pair<long long,long long> P = make_pair(0,-100000000000000000);
	
    i64 ans = 0;
    for(int i = 0; i < v[0].size(); ++i){
		P.first = -v[0][i].first;
        auto it = lower_bound(v[1].begin(), v[1].end(), P);
        if(it == v[1].end()){
            continue;
        }
        int idx = distance(v[1].begin(), it);
        ans = max(ans, v[0][i].second + v[1][idx].second);
    }

     for(int i = 0; i < special[0].size(); ++i){
		P.first = -special[0][i].first;
        auto it = lower_bound(special[1].begin(), special[1].end(), P);
        if(it == special[1].end()){
            continue;
        }
        int idx = distance(special[1].begin(), it);
        ans = max(ans, special[0][i].second + special[1][idx].second);
    }

    /*
    for(int i = 0; i < 2; ++i){
        for(auto &x : v_keys[i])
            cout << x << " ";
        cout << endl;
        for(auto &x : v_vals[i])
            cout << x << " ";
        cout << endl;
        cout << endl;
    }
     */

    cout << ans << endl;
}
0