結果
問題 | No.2866 yuusaan's Knapsack |
ユーザー | PNJ |
提出日時 | 2024-09-03 02:22:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 209 ms / 2,000 ms |
コード長 | 867 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 82,040 KB |
実行使用メモリ | 107,720 KB |
最終ジャッジ日時 | 2024-09-03 02:22:41 |
合計ジャッジ時間 | 6,003 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
69,080 KB |
testcase_01 | AC | 69 ms
71,568 KB |
testcase_02 | AC | 73 ms
72,964 KB |
testcase_03 | AC | 58 ms
66,136 KB |
testcase_04 | AC | 55 ms
64,372 KB |
testcase_05 | AC | 56 ms
64,700 KB |
testcase_06 | AC | 194 ms
106,104 KB |
testcase_07 | AC | 168 ms
100,184 KB |
testcase_08 | AC | 179 ms
104,484 KB |
testcase_09 | AC | 177 ms
102,200 KB |
testcase_10 | AC | 177 ms
104,164 KB |
testcase_11 | AC | 150 ms
96,176 KB |
testcase_12 | AC | 175 ms
100,896 KB |
testcase_13 | AC | 162 ms
97,816 KB |
testcase_14 | AC | 172 ms
101,400 KB |
testcase_15 | AC | 182 ms
104,548 KB |
testcase_16 | AC | 168 ms
97,896 KB |
testcase_17 | AC | 192 ms
103,304 KB |
testcase_18 | AC | 165 ms
94,916 KB |
testcase_19 | AC | 209 ms
107,720 KB |
testcase_20 | AC | 191 ms
100,508 KB |
testcase_21 | AC | 195 ms
101,764 KB |
testcase_22 | AC | 179 ms
99,916 KB |
testcase_23 | AC | 202 ms
106,268 KB |
testcase_24 | AC | 172 ms
99,268 KB |
testcase_25 | AC | 184 ms
102,928 KB |
testcase_26 | AC | 168 ms
104,524 KB |
testcase_27 | AC | 73 ms
74,176 KB |
ソースコード
inf = 1 << 61 mod = 998244353 N,W = map(int,input().split()) B = [] for i in range(N): v,w = map(int,input().split()) B.append((w,v)) B.sort() dp = [[-inf for w in range(20001)] for n in range(N + 1)] C = [[0 for c in range(20001)] for n in range(N + 1)] dp[0][0] = 0 C[0][0] = 1 for i in range(N): for w in range(-10000,10001): dp[i + 1][w] = dp[i][w] C[i + 1][w] = C[i][w] w,v = B[i] for ww in range(-10000,10001): if -10000 <= w + ww <= 10000: if dp[i][ww] + v > dp[i + 1][w + ww]: dp[i + 1][w + ww] = dp[i][ww] + v C[i + 1][w + ww] = C[i][ww] elif dp[i][ww] + v == dp[i + 1][w + ww]: C[i + 1][w + ww] = (C[i + 1][w + ww] + C[i][ww]) % mod V = -inf for w in range(-10000,W + 1): V = max(dp[N][w],V) ans = 0 for w in range(-10000,W + 1): if V == dp[N][w]: ans += C[N][w] ans %= mod print(V,ans)