結果

問題 No.2617 容量3のナップザック
ユーザー ococonomy1ococonomy1
提出日時 2024-01-26 22:15:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,894 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 121,224 KB
実行使用メモリ 51,896 KB
最終ジャッジ日時 2024-01-26 22:15:17
合計ジャッジ時間 6,493 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 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 WA -
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 98 ms
27,152 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 9 ms
6,676 KB
testcase_25 AC 90 ms
29,992 KB
testcase_26 AC 104 ms
28,068 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 55 ms
18,624 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 186 ms
51,896 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 158 ms
49,156 KB
testcase_40 WA -
testcase_41 AC 77 ms
43,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll,int>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
// #define AMARI 1000000007
#define TIME_LIMIT 1980000
#define el '\n'
#define El '\n'

#define MULTI_TEST_CASE false
void solve(void) {
    //問題を見たらまず「この問題設定から言えること」をいっぱい言ってみる
    //一個解答に繋がりそうな解法が見えても、実装や細かい考察に時間がかかりそうなら別の方針やを考えてみる
    //特に添え字周りはそのままやると面倒&言い換えが有効なことが多いので書き始める前にじっくり考える
    int n,k;
    ll m,a,b,seed;
    cin >> n >> k >> seed >> a >> b >> m;
    vector<ll> f(2 * n);
    f[0] = seed;
    for(int i = 0; i < 2 * n - 1; i++){
        f[i + 1] = (a * f[i] + b) % m;
    }
    vector<ll> v(n),w(n);
    vector<ll> one,two,three;
    for(int i = 0; i < n; i++){
        w[i] = f[i] % 3 + 1;
        v[i] = w[i] * f[i + n];
        if(w[i] == 1)one.push_back(v[i]);
        if(w[i] == 2)two.push_back(v[i]);
        if(w[i] == 3)three.push_back(v[i]);
    }

    sort(one.begin(),one.end());
    sort(two.begin(),two.end());

    while(!two.empty()){
        ll ot = 0,ooo = 0;

        if(one.size() >= 1)ooo += one[one.size() - 1];
        if(one.size() >= 2)ooo += one[one.size() - 2];
        if(one.size() >= 3)ooo += one[one.size() - 3];
        
        if(one.size() >= 1)ot += one[one.size() - 1];
        if(two.size() >= 1)ot += two[two.size() - 1];
        if(ot >= ooo){
            three.push_back(ot);
            if(!one.empty())one.pop_back(); 
            if(!two.empty())two.pop_back();
        }
        else{
            three.push_back(ooo);
            for(int i = 0; i < 3 && !one.empty(); i++)one.pop_back();
        }
    }
    while(!one.empty()){
        ll temp = 0;
        for(int i = 0; i < 3 && !one.empty(); i++){
            temp += one.back();
            one.pop_back();
        }
        three.push_back(temp);
    }
    sort(three.rbegin(),three.rend());
    ll ans = 0;
    for(int i = 0; i < three.size(); i++){
        if(i >= k)break;
        ans += three[i];
    }
    cout << ans << El;
    return;
}

void calc(void) {
    return;
}

signed main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE) cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
0