結果

問題 No.247 線形計画問題もどき
ユーザー rlangevinrlangevin
提出日時 2023-08-17 08:58:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 283 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 76,720 KB
最終ジャッジ日時 2023-08-17 08:58:44
合計ジャッジ時間 4,185 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
76,524 KB
testcase_01 AC 75 ms
76,092 KB
testcase_02 AC 200 ms
76,664 KB
testcase_03 AC 68 ms
71,260 KB
testcase_04 AC 68 ms
71,536 KB
testcase_05 AC 70 ms
71,456 KB
testcase_06 AC 68 ms
71,184 KB
testcase_07 AC 76 ms
76,656 KB
testcase_08 AC 72 ms
76,500 KB
testcase_09 AC 67 ms
71,536 KB
testcase_10 AC 70 ms
76,476 KB
testcase_11 AC 66 ms
71,260 KB
testcase_12 AC 66 ms
71,072 KB
testcase_13 AC 66 ms
71,512 KB
testcase_14 AC 71 ms
71,288 KB
testcase_15 AC 67 ms
71,296 KB
testcase_16 AC 69 ms
71,500 KB
testcase_17 AC 89 ms
76,416 KB
testcase_18 AC 77 ms
75,848 KB
testcase_19 AC 110 ms
76,720 KB
testcase_20 AC 133 ms
76,684 KB
testcase_21 AC 77 ms
76,048 KB
testcase_22 AC 85 ms
76,336 KB
testcase_23 AC 80 ms
76,012 KB
testcase_24 AC 136 ms
76,560 KB
testcase_25 AC 116 ms
76,716 KB
testcase_26 AC 81 ms
76,448 KB
testcase_27 AC 86 ms
76,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

C = int(input())
N = int(input())
A = list(map(int, input().split()))
inf = 10 ** 18
dp = [inf] * (C + 1)
dp[0] = 0
for i in range(N):
    for c in range(C + 1):
        if c - A[i] >= 0:
            dp[c] = min(dp[c], dp[c - A[i]] + 1)

print(dp[-1]) if dp[-1] != inf else print(-1)
0