結果
問題 | No.2866 yuusaan's Knapsack |
ユーザー | tassei903 |
提出日時 | 2024-08-30 21:31:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 909 ms / 2,000 ms |
コード長 | 1,334 bytes |
コンパイル時間 | 393 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 258,944 KB |
最終ジャッジ日時 | 2024-09-26 14:34:48 |
合計ジャッジ時間 | 16,330 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n, W = na() v,w = zip(*[na() for _ in range(n)]) m = 10000 M = 2 * 10 ** 5 inf = 10**18 mod = 998244353 dp = [-inf] * (M + 1) dp[m] = 0 dpcnt = [0] * (M + 1) dpcnt[m] = 1 for i in range(n): ndp = [-inf] * (M + 1) ndpcnt = [0] * (M + 1) dp, ndp = ndp, dp dpcnt, ndpcnt = ndpcnt, dpcnt for j in range(M+1): if 0 <= j + w[i] <= M: if dp[j+w[i]] < ndp[j] + v[i]: dp[j+w[i]] = ndp[j] + v[i] dpcnt[j+w[i]] = ndpcnt[j] elif dp[j+w[i]] == ndp[j] + v[i]: dpcnt[j+w[i]] += ndpcnt[j] dpcnt[j+w[i]] %= mod if dp[j] < ndp[j]: dp[j] = ndp[j] dpcnt[j] = ndpcnt[j] elif dp[j] == ndp[j]: dpcnt[j] += ndpcnt[j] dpcnt[j] %= mod #print(dp) #print(dpcnt) ans = max(dp[:m + W + 1]) ans_cnt = 0 for i in range(m + W + 1): if dp[i] == ans: ans_cnt += dpcnt[i] ans_cnt %= mod print(ans, ans_cnt)