結果

問題 No.247 線形計画問題もどき
ユーザー tassei903tassei903
提出日時 2021-10-10 23:10:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 78,068 KB
最終ジャッジ日時 2023-10-12 20:56:02
合計ジャッジ時間 5,704 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
77,840 KB
testcase_01 AC 94 ms
71,632 KB
testcase_02 AC 105 ms
77,892 KB
testcase_03 AC 93 ms
71,536 KB
testcase_04 AC 93 ms
71,536 KB
testcase_05 AC 92 ms
71,424 KB
testcase_06 AC 92 ms
71,656 KB
testcase_07 AC 96 ms
77,052 KB
testcase_08 AC 104 ms
78,056 KB
testcase_09 AC 91 ms
71,452 KB
testcase_10 AC 97 ms
77,072 KB
testcase_11 AC 93 ms
71,544 KB
testcase_12 AC 93 ms
71,536 KB
testcase_13 AC 93 ms
71,416 KB
testcase_14 AC 93 ms
71,292 KB
testcase_15 AC 93 ms
71,552 KB
testcase_16 AC 93 ms
71,548 KB
testcase_17 AC 109 ms
77,520 KB
testcase_18 AC 105 ms
77,180 KB
testcase_19 AC 108 ms
77,860 KB
testcase_20 AC 144 ms
77,968 KB
testcase_21 AC 97 ms
76,156 KB
testcase_22 AC 104 ms
77,424 KB
testcase_23 AC 95 ms
76,532 KB
testcase_24 AC 143 ms
78,068 KB
testcase_25 AC 130 ms
77,880 KB
testcase_26 AC 101 ms
77,668 KB
testcase_27 AC 103 ms
77,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

c = ni()
n = ni()
a = na()
a = sorted(set(a))
n = len(a)
from collections import deque
d = deque([0])
inf = 10**9
dp = [inf for i in range(c+1)]
dp[0] = 0
while d:
    e = d.popleft()
    for i in a:
        if i+e>c:
            break
        if dp[i+e]!=inf:continue
        dp[i+e] = dp[e]+1
        d.append(i+e)
if dp[-1]==inf:
    print(-1)
else:
    print(dp[-1])
0