結果

問題 No.247 線形計画問題もどき
ユーザー e-mone-mon
提出日時 2015-07-19 00:42:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 76,908 KB
最終ジャッジ日時 2023-09-21 17:28:04
合計ジャッジ時間 4,295 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
76,648 KB
testcase_01 AC 76 ms
75,644 KB
testcase_02 AC 221 ms
76,884 KB
testcase_03 AC 73 ms
71,052 KB
testcase_04 AC 73 ms
71,212 KB
testcase_05 AC 75 ms
71,356 KB
testcase_06 AC 74 ms
71,248 KB
testcase_07 AC 80 ms
76,732 KB
testcase_08 AC 79 ms
76,776 KB
testcase_09 AC 73 ms
71,488 KB
testcase_10 AC 78 ms
76,680 KB
testcase_11 AC 73 ms
71,384 KB
testcase_12 AC 73 ms
71,500 KB
testcase_13 AC 73 ms
71,460 KB
testcase_14 AC 72 ms
71,256 KB
testcase_15 AC 73 ms
71,180 KB
testcase_16 AC 72 ms
71,340 KB
testcase_17 AC 97 ms
76,416 KB
testcase_18 AC 81 ms
76,152 KB
testcase_19 AC 109 ms
76,492 KB
testcase_20 AC 160 ms
76,600 KB
testcase_21 AC 79 ms
76,144 KB
testcase_22 AC 86 ms
76,272 KB
testcase_23 AC 78 ms
75,924 KB
testcase_24 AC 140 ms
76,908 KB
testcase_25 AC 126 ms
76,548 KB
testcase_26 AC 88 ms
76,424 KB
testcase_27 AC 85 ms
76,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
# -*- coding: utf-8 -*-

C = int(input())
N = int(input())
A = list(map(int,input().split()))

dp = [-1 for i in range(C+1)]
dp[0] = 0

for i in range(N):
    for j in range(C+1):
        if dp[j] >= 0 and j + A[i] <= C:
            if dp[j + A[i]] != -1:
                dp[j + A[i]] = min(dp[j + A[i]], dp[j] + 1)
            else:
                dp[j + A[i]] = dp[j] + 1
print(dp[C])

0