結果

問題 No.247 線形計画問題もどき
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-22 00:18:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 257 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 60,168 KB
最終ジャッジ日時 2023-10-21 12:11:36
合計ジャッジ時間 2,543 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
59,792 KB
testcase_01 AC 41 ms
59,376 KB
testcase_02 AC 112 ms
60,164 KB
testcase_03 AC 38 ms
53,308 KB
testcase_04 AC 37 ms
53,308 KB
testcase_05 AC 37 ms
53,308 KB
testcase_06 AC 38 ms
53,308 KB
testcase_07 AC 43 ms
60,160 KB
testcase_08 AC 43 ms
60,160 KB
testcase_09 AC 37 ms
53,308 KB
testcase_10 AC 38 ms
54,092 KB
testcase_11 AC 38 ms
53,308 KB
testcase_12 AC 38 ms
53,308 KB
testcase_13 AC 37 ms
53,308 KB
testcase_14 AC 38 ms
53,308 KB
testcase_15 AC 38 ms
53,308 KB
testcase_16 AC 39 ms
53,308 KB
testcase_17 AC 46 ms
59,696 KB
testcase_18 AC 44 ms
59,388 KB
testcase_19 AC 53 ms
59,908 KB
testcase_20 AC 60 ms
60,040 KB
testcase_21 AC 41 ms
59,376 KB
testcase_22 AC 43 ms
59,528 KB
testcase_23 AC 43 ms
59,388 KB
testcase_24 AC 61 ms
60,168 KB
testcase_25 AC 54 ms
59,920 KB
testcase_26 AC 44 ms
59,796 KB
testcase_27 AC 44 ms
59,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

inf = 10**9
C = int(input())
N = int(input())
A = list(map(int, input().split()))

dp = [inf] * (C + 1)
dp[0] = 0
for a in A:
    for i in range(C - a + 1):
        dp[i + a] = min(dp[i + a], dp[i] + 1)

if dp[C] >= inf:
    print(-1)
else:
    print(dp[C])
0