結果
問題 | No.2866 yuusaan's Knapsack |
ユーザー | haihamabossu |
提出日時 | 2024-08-30 22:15:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,271 bytes |
コンパイル時間 | 2,274 ms |
コンパイル使用メモリ | 212,612 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-31 01:28:20 |
合計ジャッジ時間 | 3,053 ms |
ジャッジサーバーID (参考情報) |
judge2 / 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,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 7 ms
6,944 KB |
testcase_07 | AC | 6 ms
6,944 KB |
testcase_08 | AC | 6 ms
6,940 KB |
testcase_09 | AC | 7 ms
6,944 KB |
testcase_10 | AC | 6 ms
6,944 KB |
testcase_11 | AC | 5 ms
6,944 KB |
testcase_12 | AC | 6 ms
6,940 KB |
testcase_13 | AC | 6 ms
6,940 KB |
testcase_14 | AC | 6 ms
6,944 KB |
testcase_15 | AC | 7 ms
6,940 KB |
testcase_16 | AC | 6 ms
6,944 KB |
testcase_17 | AC | 6 ms
6,944 KB |
testcase_18 | AC | 5 ms
6,940 KB |
testcase_19 | AC | 7 ms
6,944 KB |
testcase_20 | AC | 6 ms
6,940 KB |
testcase_21 | AC | 6 ms
6,944 KB |
testcase_22 | AC | 6 ms
6,944 KB |
testcase_23 | AC | 7 ms
6,944 KB |
testcase_24 | AC | 6 ms
6,944 KB |
testcase_25 | AC | 6 ms
6,940 KB |
testcase_26 | AC | 6 ms
6,940 KB |
testcase_27 | AC | 3 ms
6,940 KB |
ソースコード
#include <atcoder/modint> #include <bits/stdc++.h> using namespace std; using ll = long long; using mint = atcoder::modint998244353; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll INF = 1e18, MX = 20020; void solve() { ll n, W; cin >> n >> W; vector<pair<ll, ll>> wv(n); rep(i, n) cin >> wv[i].second >> wv[i].first; sort(wv.begin(), wv.end()); vector<pair<ll, mint>> dp(MX + 10, {-INF, -INF}); dp[MX / 2] = {0, 1}; for (const auto [w, v] : wv) { vector<pair<ll, mint>> nex = dp; rep(pw, MX) { ll nw = pw + w; if (0 <= nw && nw <= MX) { if (nex[nw].first < dp[pw].first + v) { nex[nw] = {dp[pw].first + v, dp[pw].second}; } else if (nex[nw].first == dp[pw].first + v) { nex[nw].second += dp[pw].second; } } } swap(dp, nex); } ll maxv = -INF; mint ans = 0; for (ll i = 0; i <= W + MX / 2; i++) { if (maxv < dp[i].first) { maxv = dp[i].first; ans = dp[i].second; } else if (maxv == dp[i].first) { ans += dp[i].second; } } cout << maxv << ' ' << ans.val() << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }