結果
問題 | No.2866 yuusaan's Knapsack |
ユーザー | Tatsu_mr |
提出日時 | 2024-08-30 23:18:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,554 bytes |
コンパイル時間 | 4,943 ms |
コンパイル使用メモリ | 270,368 KB |
実行使用メモリ | 27,500 KB |
最終ジャッジ日時 | 2024-08-30 23:18:36 |
合計ジャッジ時間 | 6,492 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,816 KB |
testcase_01 | AC | 3 ms
6,944 KB |
testcase_02 | AC | 4 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | AC | 29 ms
26,240 KB |
testcase_07 | AC | 25 ms
21,736 KB |
testcase_08 | AC | 29 ms
24,832 KB |
testcase_09 | AC | 25 ms
23,168 KB |
testcase_10 | AC | 29 ms
24,680 KB |
testcase_11 | AC | 20 ms
18,432 KB |
testcase_12 | AC | 25 ms
22,144 KB |
testcase_13 | AC | 22 ms
19,820 KB |
testcase_14 | AC | 25 ms
22,400 KB |
testcase_15 | WA | - |
testcase_16 | AC | 22 ms
19,692 KB |
testcase_17 | AC | 27 ms
23,660 KB |
testcase_18 | AC | 20 ms
17,536 KB |
testcase_19 | AC | 31 ms
27,008 KB |
testcase_20 | AC | 24 ms
21,248 KB |
testcase_21 | AC | 25 ms
22,528 KB |
testcase_22 | AC | 24 ms
21,248 KB |
testcase_23 | AC | 30 ms
26,112 KB |
testcase_24 | AC | 23 ms
20,840 KB |
testcase_25 | AC | 27 ms
23,660 KB |
testcase_26 | AC | 30 ms
27,500 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:16:12: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] 16 | w[i]; | ^ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:64, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/functional:62, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:71, from main.cpp:1: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:1121:7: note: declared here 1121 | operator[](size_type __n) _GLIBCXX_NOEXCEPT | ^~~~~~~~
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using lint = long long; using mint = atcoder::modint998244353; lint INF = 2000000000; int main() { int n, W; cin >> n >> W; vector<lint> v(n), w(n); for (int i = 0; i < n; i++) { cin >> v[i] >> w[i]; w[i]; } vector<vector<lint>> dp(n + 1, vector<lint>(20010, -INF)); dp[0][10000] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < 20010; j++) { dp[i][j] = max(dp[i][j], dp[i - 1][j]); if (0 <= j - w[i - 1] && j - w[i - 1] < 20010) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]); } } } lint ans = -INF; for (int j = 0; j <= W + 10000; j++) { ans = max(ans, dp[n][j]); } vector<vector<mint>> cnt(n + 1, vector<mint>(20010)); for (int j = 0; j < 20010; j++) { if (dp[n][j] == ans) { cnt[n][j] = 1; } } for (int i = n; i >= 1; i--) { for (int j = 0; j < 20010; j++) { if (0 <= j - w[i - 1] && j - w[i - 1] < 20010) { if (dp[i - 1][j] == dp[i][j]) { cnt[i - 1][j] += cnt[i][j]; } if (dp[i - 1][j - w[i - 1]] == dp[i][j] - v[i - 1]) { cnt[i - 1][j - w[i - 1]] += cnt[i][j]; } } } } mint ans2 = 0; for (int j = 0; j < 20010; j++) { ans2 += cnt[0][j]; } cout << ans << " " << ans2.val() << endl; }