結果

問題 No.385 カップ麺生活
ユーザー ebicochineal
提出日時 2016-07-02 08:58:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 715 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 219,096 KB
最終ジャッジ日時 2024-10-12 02:21:58
合計ジャッジ時間 7,804 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_number_list(n): 
    l = [2, 3]
    if n < 5 : return l 
    for i in range(5, n+1, 2):
        if all([0 if i % x == 0 else 1 for x in l]):
            l += [i]
    return l

M = int(input())
N = int(input())
C = sorted(list(map(int, input().split())))
p = set(prime_number_list(M))
ans = M // min(C)
q = [0]
cnt = 0
d = {}
c = [C[0]]
for i in range(1, len(C)):
    if all([0 if C[i] % x == 0 else 1 for x in C[:i]]):
        c += [C[i]]
while q:
    cnt += 1
    l = []
    for i in set(q):
        for j in c:
            a = i + j
            if a <= M:
                 l += [a]
                 if M - a in p:
                    d[M - a] = cnt
    q = l
for i in d.values():
    ans += i
print(ans)
0