結果

問題 No.2617 容量3のナップザック
ユーザー Today03Today03
提出日時 2024-01-26 23:01:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,245 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 215,324 KB
実行使用メモリ 52,004 KB
最終ジャッジ日時 2024-01-26 23:01:39
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
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 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 80 ms
18,856 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 WA -
testcase_40 WA -
testcase_41 AC 67 ms
44,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

int main() {
    int N, K;
    ll seed, a, b, m;
    cin >> N >> K >> seed >> a >> b >> m;
    vector<ll> F(2 * N + 1), W(N), V(N);
    F[0] = seed;
    for (int i = 0; i < 2 * N; i++) F[i + 1] = (a * F[i] + b) % m;
    for (int i = 0; i < N; i++) {
        W[i] = F[i] % 3 + 1;
        V[i] = W[i] * F[N + i];
    }

    priority_queue<ll> PQ1, PQ2, PQ3;
    for (int i = 0; i < N; i++) {
        if (W[i] == 1) {
            PQ1.push(V[i]);
        } else if (W[i] == 2) {
            PQ2.push(V[i]);
        } else {
            PQ3.push(V[i]);
        }
    }

    while (!PQ1.empty()) {
        if (PQ1.size() >= 3) {
            ll a = PQ1.top();
            PQ1.pop();
            ll b = PQ1.top();
            PQ1.pop();
            ll c = PQ1.top();
            PQ1.pop();
            if (!PQ2.empty()) {
                ll d = PQ2.top();
                PQ2.pop();
                if (b + c > d) {
                    PQ3.push(a + b + c);
                    PQ2.push(d);
                } else {
                    PQ3.push(a + d);
                    PQ1.push(b);
                    PQ1.push(c);
                }
            }
        } else if (PQ1.size() == 2) {
            ll a = PQ1.top();
            PQ1.pop();
            ll b = PQ1.top();
            PQ1.pop();
            if (!PQ2.empty()) {
                ll d = PQ2.top();
                PQ2.pop();
                if (a + b > d) {
                    PQ2.push(a + b);
                    PQ2.push(d);
                } else {
                    break;
                }
            }
        } else {
            break;
        }
    }

    while (!PQ2.empty()) {
        ll b = PQ2.top();
        PQ2.pop();
        if (!PQ1.empty()) {
            ll a = PQ1.top();
            PQ1.pop();
            PQ3.push(a + b);
        } else {
            PQ3.push(b);
        }
    }

    while (!PQ1.empty()) {
        ll a = PQ1.top();
        PQ1.pop();
        PQ3.push(a);
    }

    ll ans = 0;
    while (K-- && !PQ3.empty()) {
        ans += PQ3.top();
        PQ3.pop();
    }

    cout << ans << endl;
}
0