結果
| 問題 | No.2866 yuusaan's Knapsack |
| コンテスト | |
| ユーザー |
zjsdut
|
| 提出日時 | 2026-06-23 23:34:49 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,562 bytes |
| 記録 | |
| コンパイル時間 | 2,256 ms |
| コンパイル使用メモリ | 336,180 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-23 23:34:55 |
| 合計ジャッジ時間 | 4,354 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 10 |
ソースコード
/**
* author: zjs
* created: 23.06.2026 21:48:31
**/
#include <bits/stdc++.h>
#include <cassert> // <bits/stdc++.h> does not include cassert since GCC 16.
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, W;
cin >> N >> W;
//所选物品的任意子集的总重量在 -10000 到 W + 10000
int offset = 10000;
const int mod = 998244353;
int len = W + 20000 + 1;
const int INF = INT_MIN / 2;
vector<int> dp(len, INT_MIN);
vector<int> cnt(len);
for (int i = offset; i < len; i++) {
dp[i] = 0;
cnt[i] = 1;
}
while (N--) {
int v, w;
cin >> v >> w;
vector<int> new_dp(len, INF);
vector<int> new_cnt(len);
for (int i = 0; i < len; i++) {
if (0 <= i - w && i - w < len && dp[i - w] != INF) {
if (dp[i] < v + dp[i - w]) {
new_dp[i] = v + dp[i - w];
new_cnt[i] = cnt[i - w];
} else if (dp[i] > v + dp[i - w]) {
new_dp[i] = dp[i];
new_cnt[i] = cnt[i];
} else {
new_dp[i] = dp[i];
new_cnt[i] = (cnt[i] + cnt[i - w]) % mod;
}
} else {
new_dp[i] = dp[i];
new_cnt[i] = cnt[i];
}
}
dp = new_dp;
cnt = new_cnt;
}
cout << dp[W + offset] << ' ' << cnt[W + offset] << '\n';
}
zjsdut