結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,676 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 81 ms
24,244 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 86 ms
25,456 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 155 ms
42,924 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

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(chmax(x[i],l))
                pi-=2, pj+=1;
            else if(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