結果

問題 No.247 線形計画問題もどき
ユーザー ayaoniayaoni
提出日時 2020-11-26 15:58:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 77,172 KB
最終ジャッジ日時 2023-10-01 03:24:07
合計ジャッジ時間 4,111 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
76,460 KB
testcase_01 AC 78 ms
76,248 KB
testcase_02 AC 130 ms
76,880 KB
testcase_03 AC 77 ms
71,264 KB
testcase_04 AC 74 ms
71,020 KB
testcase_05 AC 73 ms
71,292 KB
testcase_06 AC 73 ms
71,340 KB
testcase_07 AC 86 ms
77,032 KB
testcase_08 AC 77 ms
76,872 KB
testcase_09 AC 73 ms
71,468 KB
testcase_10 AC 77 ms
76,568 KB
testcase_11 AC 71 ms
71,408 KB
testcase_12 AC 71 ms
71,320 KB
testcase_13 AC 76 ms
71,240 KB
testcase_14 AC 78 ms
71,524 KB
testcase_15 AC 73 ms
71,524 KB
testcase_16 AC 72 ms
71,392 KB
testcase_17 AC 93 ms
76,516 KB
testcase_18 AC 80 ms
76,124 KB
testcase_19 AC 113 ms
76,732 KB
testcase_20 AC 130 ms
76,968 KB
testcase_21 AC 81 ms
76,260 KB
testcase_22 AC 86 ms
76,168 KB
testcase_23 AC 85 ms
76,280 KB
testcase_24 AC 132 ms
77,172 KB
testcase_25 AC 115 ms
76,948 KB
testcase_26 AC 88 ms
76,528 KB
testcase_27 AC 91 ms
76,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


C,N = I(),I()
A = LI()
inf = 10**18

dp = [0]*(C+1)
# dp[i] = (sum(AjXj) == i 下での sum(Xj) の最小値)
for i in range(1,C+1):
    r = inf
    for j in range(N):
        a = A[j]
        if i >= a:
            r = min(r,1+dp[i-a])
    dp[i] = r

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