結果

問題 No.527 ナップサック容量問題
ユーザー ああいいああいい
提出日時 2022-03-30 18:58:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 102,776 KB
最終ジャッジ日時 2024-04-27 08:56:54
合計ジャッジ時間 4,125 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,064 KB
testcase_01 AC 44 ms
60,168 KB
testcase_02 AC 38 ms
52,332 KB
testcase_03 AC 48 ms
61,884 KB
testcase_04 AC 38 ms
53,024 KB
testcase_05 AC 58 ms
68,852 KB
testcase_06 AC 98 ms
93,852 KB
testcase_07 AC 81 ms
82,528 KB
testcase_08 AC 55 ms
67,500 KB
testcase_09 AC 39 ms
54,028 KB
testcase_10 AC 97 ms
92,572 KB
testcase_11 AC 70 ms
75,060 KB
testcase_12 AC 61 ms
69,772 KB
testcase_13 AC 101 ms
95,712 KB
testcase_14 AC 58 ms
67,300 KB
testcase_15 AC 68 ms
74,044 KB
testcase_16 AC 48 ms
61,908 KB
testcase_17 AC 61 ms
69,876 KB
testcase_18 AC 64 ms
71,492 KB
testcase_19 AC 52 ms
63,948 KB
testcase_20 AC 53 ms
65,744 KB
testcase_21 AC 107 ms
99,672 KB
testcase_22 AC 84 ms
82,728 KB
testcase_23 AC 99 ms
94,244 KB
testcase_24 AC 52 ms
63,900 KB
testcase_25 AC 72 ms
78,212 KB
testcase_26 AC 69 ms
75,128 KB
testcase_27 AC 71 ms
77,240 KB
testcase_28 AC 72 ms
75,084 KB
testcase_29 AC 109 ms
102,776 KB
testcase_30 AC 38 ms
52,404 KB
testcase_31 AC 44 ms
59,408 KB
testcase_32 AC 45 ms
60,484 KB
testcase_33 AC 45 ms
59,704 KB
testcase_34 AC 45 ms
60,352 KB
testcase_35 AC 71 ms
75,000 KB
testcase_36 AC 50 ms
63,512 KB
testcase_37 AC 62 ms
69,784 KB
testcase_38 AC 66 ms
73,852 KB
testcase_39 AC 64 ms
70,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
l = []
C = 0
for _ in range(N):
    v,w = map(int,input().split())
    l.append((v,w))
    C += w
dp = [0] * (C + 1)
V = int(input())
for v,w in l:
    nx = dp.copy()
    for j in range(C+1):
        if j + w <= C:
            if nx[j + w] < dp[j] + v:
                nx[j + w] = dp[j] + v
    dp = nx
m = C + 5
M = 0
for i in range(1,C+1):
    if dp[i] == V:
        if i < m:
            m = i
        if i > M:
            M = i
if M == C:
    M = "inf"
print(m)
print(M)
0