結果

問題 No.2617 容量3のナップザック
ユーザー KKT89KKT89
提出日時 2024-01-31 13:33:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,503 bytes
コンパイル時間 3,155 ms
コンパイル使用メモリ 221,160 KB
実行使用メモリ 39,072 KB
最終ジャッジ日時 2024-01-31 13:33:27
合計ジャッジ時間 8,204 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 81 ms
20,120 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 8 ms
6,676 KB
testcase_25 AC 87 ms
21,380 KB
testcase_26 AC 86 ms
21,028 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 55 ms
14,876 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 155 ms
35,164 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 156 ms
34,896 KB
testcase_40 WA -
testcase_41 AC 75 ms
34,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    ll seed, a, b, m;
    cin >> seed >> a >> b >> m;
    vector<ll> f(2 * n);
    f[0] = seed;
    for (int i = 1; i < 2 * n; i++) {
        f[i] = (f[i - 1] * a + b) % m;
    }
    vector<ll> v[3];
    for (int i = 0; i < n; i++) {
        int w = f[i] % 3 + 1;
        v[w - 1].push_back(w * f[n + i]);
    }
    for (int i = 0; i < 3; i++) {
        sort(v[i].rbegin(), v[i].rend());
    }

    vector<ll> dp(n + 1);
    int o = 0, t = 0;
    for (int i = 1; i <= n; i++) {
        ll p = 0, b = 0;
        if (o < v[0].size()) p += v[0][o];
        if (o + 1 < v[0].size()) p += v[0][o + 1];
        if (o + 2 < v[0].size()) p += v[0][o + 2];

        if (t < v[1].size()) b += v[1][t];
        if (o < v[0].size()) b += v[0][o];

        if (p <= b) {
            dp[i] = dp[i - 1] + b;
            t += 1, o += 1;
        } else {
            dp[i] = dp[i - 1] + p;
            o += 3;
        }
    }

    ll res = 0;
    ll sum = 0;
    for (int i = 0; i <= v[2].size(); i++) {
        if (i > k) break;
        res = max(res, sum + dp[k - i]);
        if (i == v[2].size()) break;
        sum += v[2][i];
    }
    cout << res << endl;
}
0