結果

問題 No.2866 yuusaan's Knapsack
ユーザー mkawa2mkawa2
提出日時 2024-08-30 22:23:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,447 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 80,984 KB
最終ジャッジ日時 2024-08-31 01:28:28
合計ジャッジ時間 4,594 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
66,580 KB
testcase_01 AC 50 ms
66,028 KB
testcase_02 AC 55 ms
69,756 KB
testcase_03 AC 45 ms
63,040 KB
testcase_04 AC 45 ms
63,472 KB
testcase_05 AC 46 ms
63,760 KB
testcase_06 AC 157 ms
79,336 KB
testcase_07 AC 146 ms
79,528 KB
testcase_08 AC 159 ms
79,444 KB
testcase_09 AC 147 ms
79,784 KB
testcase_10 AC 148 ms
78,808 KB
testcase_11 AC 135 ms
79,568 KB
testcase_12 AC 141 ms
79,664 KB
testcase_13 AC 146 ms
80,036 KB
testcase_14 AC 145 ms
79,180 KB
testcase_15 AC 149 ms
79,044 KB
testcase_16 AC 164 ms
79,888 KB
testcase_17 AC 176 ms
80,336 KB
testcase_18 AC 159 ms
80,276 KB
testcase_19 AC 174 ms
79,456 KB
testcase_20 AC 175 ms
80,868 KB
testcase_21 AC 170 ms
79,788 KB
testcase_22 AC 164 ms
79,700 KB
testcase_23 AC 187 ms
80,984 KB
testcase_24 AC 164 ms
79,412 KB
testcase_25 AC 177 ms
79,756 KB
testcase_26 AC 71 ms
69,940 KB
testcase_27 AC 53 ms
68,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

def update(i,v,w):
    if dp[i][1]==0:return
    ni=i+w
    if dp[ni][0]==dp[i][0]+v:
        dp[ni][1]+=dp[i][1]
    if dp[ni][0]<dp[i][0]+v:
        dp[ni][0]=dp[i][0]+v
        dp[ni][1]=dp[i][1]
    dp[ni][1]%=md

N,W=LI()
nW=W+N*10000
dp=[[-inf,0] for _ in range(W+20005)]
dp[0]=[0,1]

for _ in range(N):
    v,w=LI()
    if w<0:
        for i in range(-10000-w,W+10001):
            update(i,v,w)
    else:
        for i in range(W+10000-w,-10001,-1):
            update(i,v,w)

ans=[-inf,0]
for i in range(-10000,W+1):
    if dp[i][0]==ans[0]:
        ans[1]+=dp[i][1]
        ans[1]%=md
    if dp[i][0]>ans[0]:
        ans[0]=dp[i][0]
        ans[1]=dp[i][1]

print(*ans)
0