結果

問題 No.247 線形計画問題もどき
ユーザー NoneNone
提出日時 2021-04-29 02:42:36
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 276 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 76,684 KB
最終ジャッジ日時 2023-09-22 09:38:16
合計ジャッジ時間 4,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
76,188 KB
testcase_01 AC 71 ms
75,604 KB
testcase_02 AC 113 ms
76,536 KB
testcase_03 AC 68 ms
71,044 KB
testcase_04 AC 75 ms
71,288 KB
testcase_05 AC 69 ms
71,036 KB
testcase_06 AC 70 ms
71,484 KB
testcase_07 AC 73 ms
76,436 KB
testcase_08 AC 75 ms
76,684 KB
testcase_09 AC 69 ms
71,216 KB
testcase_10 AC 69 ms
72,296 KB
testcase_11 AC 68 ms
71,232 KB
testcase_12 AC 70 ms
71,292 KB
testcase_13 AC 70 ms
71,368 KB
testcase_14 AC 69 ms
71,304 KB
testcase_15 AC 68 ms
71,532 KB
testcase_16 AC 69 ms
71,312 KB
testcase_17 AC 78 ms
76,284 KB
testcase_18 AC 75 ms
76,048 KB
testcase_19 AC 79 ms
76,308 KB
testcase_20 AC 104 ms
76,560 KB
testcase_21 AC 72 ms
75,464 KB
testcase_22 AC 73 ms
75,944 KB
testcase_23 AC 73 ms
75,604 KB
testcase_24 AC 97 ms
76,484 KB
testcase_25 AC 90 ms
76,416 KB
testcase_26 AC 72 ms
76,308 KB
testcase_27 AC 73 ms
76,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

C=int(input())
N=int(input())
INF=10**18
dp=[INF]*(C+1)
dp[0]=0
A=list(map(int, input().split()))
for i,a in enumerate(A):
    for w in range(C+1-a):
        if dp[w]!=INF or w==0:
            dp[w+a]=min(dp[w]+1,dp[w+a])

if dp[-1]==INF:
    print(-1)
else:
    print(dp[-1])
0