結果

問題 No.247 線形計画問題もどき
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-28 16:52:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,031 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 81,040 KB
最終ジャッジ日時 2023-09-21 17:39:02
合計ジャッジ時間 7,021 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 250 ms
78,740 KB
testcase_01 AC 73 ms
76,068 KB
testcase_02 AC 1,031 ms
81,040 KB
testcase_03 AC 69 ms
71,620 KB
testcase_04 AC 68 ms
71,692 KB
testcase_05 AC 69 ms
71,716 KB
testcase_06 AC 69 ms
71,704 KB
testcase_07 AC 113 ms
80,640 KB
testcase_08 AC 95 ms
80,684 KB
testcase_09 AC 69 ms
71,524 KB
testcase_10 AC 82 ms
78,876 KB
testcase_11 AC 70 ms
71,724 KB
testcase_12 AC 69 ms
71,528 KB
testcase_13 AC 69 ms
71,532 KB
testcase_14 AC 69 ms
71,372 KB
testcase_15 AC 68 ms
71,584 KB
testcase_16 AC 69 ms
71,500 KB
testcase_17 AC 182 ms
78,432 KB
testcase_18 AC 89 ms
77,356 KB
testcase_19 AC 433 ms
79,344 KB
testcase_20 AC 594 ms
79,924 KB
testcase_21 AC 105 ms
77,208 KB
testcase_22 AC 148 ms
78,004 KB
testcase_23 AC 111 ms
77,332 KB
testcase_24 AC 622 ms
80,592 KB
testcase_25 AC 446 ms
79,436 KB
testcase_26 AC 150 ms
79,020 KB
testcase_27 AC 172 ms
78,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import array
import itertools


IMPOSSIBLE = -1
INF = 10 ** 6


def compute_min(c, n, bs):
    dp = array.array("L", (INF for _ in range(c + 1)))
    dp[0] = 0
    for i, b in itertools.product(range(1, c + 1), bs):
        if b <= i:
            dp[i] = min(dp[i], dp[i - b] + 1)
    return dp[c] if dp[c] < INF else IMPOSSIBLE


def main():
    c = int(input())
    n = int(input())
    bs = array.array("L", map(int, input().split()))
    print(compute_min(c, n, bs))


if __name__ == '__main__':
    main()
0