結果
| 問題 |
No.2866 yuusaan's Knapsack
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-30 21:53:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 1,509 bytes |
| コンパイル時間 | 4,369 ms |
| コンパイル使用メモリ | 297,736 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-26 14:35:27 |
| 合計ジャッジ時間 | 6,785 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#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);
}