結果

問題 No.527 ナップサック容量問題
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-15 13:14:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 837 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 114,404 KB
最終ジャッジ日時 2023-08-22 09:22:54
合計ジャッジ時間 7,498 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,376 KB
testcase_01 AC 74 ms
75,656 KB
testcase_02 AC 70 ms
71,444 KB
testcase_03 WA -
testcase_04 AC 72 ms
71,372 KB
testcase_05 AC 112 ms
82,680 KB
testcase_06 AC 192 ms
106,884 KB
testcase_07 AC 157 ms
95,028 KB
testcase_08 AC 100 ms
76,252 KB
testcase_09 AC 72 ms
71,456 KB
testcase_10 AC 197 ms
105,272 KB
testcase_11 AC 134 ms
88,252 KB
testcase_12 AC 112 ms
83,092 KB
testcase_13 AC 198 ms
108,732 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 77 ms
75,804 KB
testcase_17 AC 113 ms
82,716 KB
testcase_18 WA -
testcase_19 AC 76 ms
76,108 KB
testcase_20 AC 100 ms
76,128 KB
testcase_21 AC 229 ms
112,988 KB
testcase_22 AC 152 ms
95,912 KB
testcase_23 AC 194 ms
107,424 KB
testcase_24 AC 90 ms
76,356 KB
testcase_25 AC 139 ms
91,800 KB
testcase_26 AC 136 ms
88,748 KB
testcase_27 AC 136 ms
90,456 KB
testcase_28 AC 131 ms
87,908 KB
testcase_29 AC 223 ms
114,404 KB
testcase_30 AC 71 ms
71,224 KB
testcase_31 AC 86 ms
76,304 KB
testcase_32 AC 92 ms
76,832 KB
testcase_33 AC 86 ms
76,208 KB
testcase_34 AC 91 ms
76,104 KB
testcase_35 WA -
testcase_36 AC 76 ms
76,020 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
m=[list(map(int,input().split())) for i in range(n)]
maxw=0
for i in range(n):
    maxw += m[i][1]
v = int(input())
dp=[[-1]*(maxw+1) for i in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(maxw+1):
        if dp[i%2][j] == -1:
            continue
        dp[(i+1)%2][j] = max(dp[(i+1)%2][j],dp[i%2][j])
        if j + m[i][1] <= len(dp[0])-1:
            dp[(i+1)%2][j+m[i][1]] = max(dp[(i+1)%2][j+m[i][1]],dp[i%2][j] + m[i][0])

ans=[]
for i in range(maxw+1):
    if dp[n%2][i] == v:
        while dp[n%2][i] <= v:
            ans.append(i)
            i+=1
            if i >= maxw+1:
                break
# print(dp[n%2])
                
if dp[n%2][-1] == v:
    print(maxw)
    print('inf')
else:
    print(1 if ans[0] == 0 else ans[0]  )
    print(ans[-1])
                
            
    
    
0