結果

問題 No.2617 容量3のナップザック
ユーザー kokoseikokosei
提出日時 2024-01-27 17:14:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,698 bytes
コンパイル時間 3,903 ms
コンパイル使用メモリ 279,936 KB
実行使用メモリ 77,804 KB
最終ジャッジ日時 2024-01-27 17:15:17
合計ジャッジ時間 30,411 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,548 KB
testcase_06 WA -
testcase_07 AC 3 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 WA -
testcase_10 AC 3 ms
6,548 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 22 ms
8,452 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 315 ms
31,212 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1,376 ms
77,804 KB
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using ll = long long;
using namespace __gnu_pbds;
template <typename T, typename F = less<T>>
using nset = tree<T, null_type, F, rb_tree_tag, tree_order_statistics_node_update>;
const int mod = 998244353;

int N, K;
ll V[1010101];
int W[1010101];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N >> K;
    {
        ll s, a, b, m;
        cin >> s >> a >> b >> m;
        for(int i = 0;i < N;i++){
            W[i] = s % 3 + 1;
            s = (s * a + b) % m;
        }
        for(int i = 0;i < N;i++){
            V[i] = s * W[i];
            s = (s * a + b) % m;
        }
    }
    nset<ll, greater<ll>> st[3];
    for(int i = 0;i < N;i++){
        st[W[i] - 1].insert(V[i]);
    }
    ll ans = 0;
    for(int i = 0;i < K;i++){
        vector<ll> a;
        a.push_back((st[0].size() < 3 ? 0 : *st[0].find_by_order(0) + *st[0].find_by_order(1) + *st[0].find_by_order(2)));
        a.push_back((st[0].empty() || st[1].empty() ? 0 : *st[0].find_by_order(0) + *st[1].find_by_order(0)));
        a.push_back((st[2].empty() ? 0 : *st[2].find_by_order(0)));
        int idx = max_element(a.begin(), a.end()) - a.begin();
        if(a[idx] == 0)break;
        ans += a[idx];
        if(idx == 0){
            st[0].erase(st[0].begin());
            st[0].erase(st[0].begin());
            st[0].erase(st[0].begin());
        }else if(idx == 1){
            st[0].erase(st[0].begin());
            st[1].erase(st[1].begin());
        }else{
            st[2].erase(st[2].begin());
        }
    }
    cout << ans << endl;
    return 0;
}
0