結果

問題 No.2866 yuusaan's Knapsack
ユーザー SnowBeenDidingSnowBeenDiding
提出日時 2024-08-30 22:32:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,421 bytes
コンパイル時間 4,787 ms
コンパイル使用メモリ 311,768 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-31 01:28:51
合計ジャッジ時間 5,707 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 8 ms
6,940 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 8 ms
6,944 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 7 ms
6,944 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 7 ms
6,944 KB
testcase_17 AC 7 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 9 ms
6,940 KB
testcase_20 AC 7 ms
6,944 KB
testcase_21 AC 7 ms
6,940 KB
testcase_22 AC 7 ms
6,944 KB
testcase_23 AC 9 ms
6,940 KB
testcase_24 AC 7 ms
6,944 KB
testcase_25 AC 8 ms
6,940 KB
testcase_26 AC 8 ms
6,944 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;
using mint = modint998244353;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    int n = v.size();
    rep(i, 0, n) { os << v[i] << " \n"[i == n - 1]; }
    return os;
}

int main() {
    ll n, w;
    cin >> n >> w;
    vector<ll> dp(30010, -2e9);
    vector<mint> pat(30010);
    int mid = 15000;
    int lim = mid + w;
    dp[mid] = 0;
    pat[mid] = 1;
    rep(i, 0, n) {
        ll nw, nv;
        cin >> nv >> nw;
        vector<ll> ndp = dp;
        vector<mint> npat = pat;

        rep(j, 0, 30010) {
            if (0 <= j + nw && j + nw < 30010) {
                if (ndp[j + nw] < dp[j] + nv) {
                    ndp[j + nw] = dp[j] + nv;
                    npat[j + nw] = pat[j];
                } else if (ndp[j + nw] == dp[j] + nv) {
                    npat[j + nw] += pat[j];
                }
            }
        }
        swap(dp, ndp);
        swap(pat, npat);
    }
    ll ans = 0;
    rep(i, 0, lim + 1) {
        if (dp[i] == -2e9)
            continue;
        if (ans < dp[i]) {
            ans = dp[i];
        }
    }
    mint pats = 0;
    rep(i, 0, lim + 1) {
        if (dp[i] == ans) {
            pats += pat[i];
        }
    }
    cout << ans << ' ' << pats.val() << endl;
}
0