結果

問題 No.2617 容量3のナップザック
ユーザー RubikunRubikun
提出日時 2024-01-26 21:41:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 2,055 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 211,412 KB
実行使用メモリ 98,936 KB
最終ジャッジ日時 2024-01-26 21:41:26
合計ジャッジ時間 8,842 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 203 ms
43,104 KB
testcase_13 AC 134 ms
27,868 KB
testcase_14 AC 186 ms
40,888 KB
testcase_15 AC 94 ms
19,144 KB
testcase_16 AC 233 ms
52,828 KB
testcase_17 AC 147 ms
31,396 KB
testcase_18 AC 132 ms
26,672 KB
testcase_19 AC 23 ms
7,648 KB
testcase_20 AC 122 ms
27,408 KB
testcase_21 AC 96 ms
22,084 KB
testcase_22 AC 138 ms
27,416 KB
testcase_23 AC 181 ms
38,440 KB
testcase_24 AC 8 ms
6,676 KB
testcase_25 AC 113 ms
27,424 KB
testcase_26 AC 253 ms
59,040 KB
testcase_27 AC 82 ms
19,224 KB
testcase_28 AC 7 ms
6,676 KB
testcase_29 AC 60 ms
15,328 KB
testcase_30 AC 135 ms
30,000 KB
testcase_31 AC 160 ms
35,084 KB
testcase_32 AC 161 ms
36,352 KB
testcase_33 AC 195 ms
41,516 KB
testcase_34 AC 216 ms
45,028 KB
testcase_35 AC 183 ms
36,392 KB
testcase_36 AC 467 ms
98,936 KB
testcase_37 AC 208 ms
47,372 KB
testcase_38 AC 157 ms
33,184 KB
testcase_39 AC 206 ms
45,920 KB
testcase_40 AC 192 ms
40,832 KB
testcase_41 AC 101 ms
37,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,K,seed,AA,BB,M;cin>>N>>K>>seed>>AA>>BB>>M;
    vector<ll> F(2*N+1);
    F[1]=seed;
    for(int i=1;i<2*N;i++) F[i+1]=(AA*F[i]+BB)%M;
    
    vector<ll> A,B,C;
    for(int i=1;i<=N;i++){
        ll w=F[i]%3+1;
        ll v=w*F[N+i];
        if(w==1) C.push_back(v);
        if(w==2) B.push_back(v);
        if(w==3) A.push_back(v);
    }
    while(si(A)<=K) A.push_back(0);
    while(si(B)<=K) B.push_back(0);
    while(si(C)<=3*K) C.push_back(0);
    
    sort(all(A));
    reverse(all(A));
    
    sort(all(B));
    reverse(all(B));
    
    sort(all(C));
    reverse(all(C));
    
    A.resize(K);
    B.resize(K);
    C.resize(3*K);
    
    ll ans=0;
    
    vector<ll> Arui(K+1),Brui(K+1),Crui(3*K+1);
    
    for(int i=1;i<=K;i++){
        Arui[i]=Arui[i-1]+A[i-1];
    }
    for(int i=1;i<=K;i++){
        Brui[i]=Brui[i-1]+B[i-1];
    }
    for(int i=1;i<=3*K;i++){
        Crui[i]=Crui[i-1]+C[i-1];
    }
    
    for(ll a=0;a<=K;a++){
        ll left=0,right=K-a;
        while(right-left>2){
            ll m1=(left+left+right)/3,m2=(left+right+right)/3;
            ll x=Arui[a]+Brui[m1]+Crui[3*K-3*a-2*m1];
            ll y=Arui[a]+Brui[m2]+Crui[3*K-3*a-2*m2];
            
            if(x>=y) right=m2;
            else left=m1;
        }
        
        for(ll b=left-2;b<=right+2;b++){
            if(0<=b&&b<=K-a){
                ll x=Arui[a]+Brui[b]+Crui[3*K-3*a-2*b];
                chmax(ans,x);
            }
        }
    }
    
    cout<<ans<<endl;
}

0