結果

問題 No.2617 容量3のナップザック
ユーザー HaaHaa
提出日時 2024-01-26 23:22:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,611 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 177,504 KB
実行使用メモリ 42,924 KB
最終ジャッジ日時 2024-01-26 23:23:04
合計ジャッジ時間 6,468 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,676 KB
testcase_04 WA -
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 WA -
testcase_11 AC 2 ms
6,676 KB
testcase_12 WA -
testcase_13 AC 130 ms
32,900 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 83 ms
24,244 KB
testcase_17 WA -
testcase_18 AC 104 ms
26,376 KB
testcase_19 WA -
testcase_20 AC 118 ms
31,564 KB
testcase_21 WA -
testcase_22 AC 133 ms
32,548 KB
testcase_23 WA -
testcase_24 AC 8 ms
6,676 KB
testcase_25 AC 84 ms
22,640 KB
testcase_26 AC 89 ms
25,456 KB
testcase_27 AC 46 ms
13,920 KB
testcase_28 WA -
testcase_29 AC 52 ms
15,372 KB
testcase_30 AC 126 ms
34,716 KB
testcase_31 AC 102 ms
26,676 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 154 ms
38,580 KB
testcase_35 WA -
testcase_36 AC 187 ms
42,924 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 152 ms
37,308 KB
testcase_40 AC 154 ms
40,232 KB
testcase_41 AC 75 ms
35,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main(){
    ll n, k, seed, a, b, m;
    cin >> n >> k >> seed >> a >> b >> m;
    VI f(2*n);
    f[0]=seed;
    REP(i,2*n-1) f[i+1]=(f[i]*a+b)%m;
    VVI v(3);
    REP(i,n){
        ll w=f[i]%3+1;
        v[w-1].push_back(w*f[n+i]);
    }
    VVI s(3);
    REP(i,3){
        sort(ALL(v[i]),greater<ll>());
        s[i].resize(v[i].size()+1);
        s[i][0]=0;
        REP(j,(int)v[i].size()){
            s[i][j+1]=s[i][j]+v[i][j];
        }
    }
    VI x(k+1,0);
    int pi=0, pj=0;
    for(int i=1;i<=k;i++){
        pi+=3;
        x[i]=s[0][min(max(0,pi),(int)s[0].size()-1)]+s[1][min(max(0,pj),(int)s[1].size()-1)];
        while(1){
            ll l=s[0][min(max(0,pi-2),(int)s[0].size()-1)]+s[1][min(max(0,pj+1),(int)s[1].size()-1)];
            ll r=s[0][min(max(0,pi+2),(int)s[0].size()-1)]+s[1][min(max(0,pj-1),(int)s[1].size()-1)];
            if(pi>=2&&chmax(x[i],l))
                pi-=2, pj+=1;
            else if(pj>=1&&chmax(x[i],r))
                pi+=2, pj-=1;
            else
                break;
        }
    }
    ll ans=0;
    REP(i,k+1){
        chmax(ans,s[2][min(i,(int)s[2].size()-1)]+x[k-i]);
    }
    cout << ans << endl;
    return 0;
}
0