結果

問題 No.2866 yuusaan's Knapsack
ユーザー nu50218nu50218
提出日時 2024-08-30 21:53:22
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,509 bytes
コンパイル時間 4,388 ms
コンパイル使用メモリ 299,708 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-31 01:27:32
合計ジャッジ時間 6,806 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 110 ms
6,940 KB
testcase_07 AC 72 ms
6,940 KB
testcase_08 AC 106 ms
6,940 KB
testcase_09 AC 86 ms
6,940 KB
testcase_10 AC 99 ms
6,940 KB
testcase_11 AC 58 ms
6,944 KB
testcase_12 AC 80 ms
6,944 KB
testcase_13 AC 67 ms
6,944 KB
testcase_14 AC 81 ms
6,944 KB
testcase_15 AC 99 ms
6,940 KB
testcase_16 AC 72 ms
6,940 KB
testcase_17 AC 100 ms
6,940 KB
testcase_18 AC 47 ms
6,944 KB
testcase_19 AC 109 ms
6,944 KB
testcase_20 AC 78 ms
6,944 KB
testcase_21 AC 88 ms
6,940 KB
testcase_22 AC 75 ms
6,944 KB
testcase_23 AC 116 ms
6,944 KB
testcase_24 AC 68 ms
6,940 KB
testcase_25 AC 101 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define debug(...) ((void)0)

#include <atcoder/modint.hpp>
using mint = atcoder::modint998244353;
namespace atcoder {
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
std::ostream& operator<<(std::ostream& os, const static_modint<m>& x) {
    return os << x.val();
}
}  // namespace atcoder

using namespace std;
using ll = long long;
using ld = long double;

void solve(int) {
    int N, W;
    cin >> N >> W;

    unordered_map<int, pair<int, mint>> dp;
    dp[0] = {0, 1};

    for (int i = 0; i < N; i++) {
        int v, w;
        cin >> v >> w;
        auto next_dp = dp;
        for (auto [weight, value] : dp) {
            if (!next_dp.contains(weight + w) || next_dp[weight + w].first < value.first + v) {
                next_dp[weight + w] = {value.first + v, value.second};
            } else if (next_dp[weight + w].first == value.first + v) {
                next_dp[weight + w].second += value.second;
            }
        }
        swap(dp, next_dp);
        debug(dp);
    }

    int ans = numeric_limits<int>::min();
    for (auto&& [weight, value] : dp) {
        if (weight <= W) {
            ans = max(ans, value.first);
        }
    }
    int cnt = 0;
    for (auto&& [weight, value] : dp) {
        if (weight <= W && value.first == ans) {
            cnt += value.second.val();
        }
    }
    cout << ans << ' ' << cnt << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve(0);
}
0