結果

問題 No.385 カップ麺生活
ユーザー tktk_snsntktk_snsn
提出日時 2020-11-29 22:35:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 827 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 65,640 KB
最終ジャッジ日時 2024-04-15 07:42:11
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,600 KB
testcase_01 AC 38 ms
52,760 KB
testcase_02 AC 39 ms
54,196 KB
testcase_03 AC 41 ms
59,360 KB
testcase_04 AC 48 ms
63,064 KB
testcase_05 AC 42 ms
58,516 KB
testcase_06 AC 53 ms
62,996 KB
testcase_07 AC 52 ms
65,148 KB
testcase_08 AC 48 ms
61,692 KB
testcase_09 AC 38 ms
53,328 KB
testcase_10 AC 50 ms
65,140 KB
testcase_11 AC 37 ms
52,412 KB
testcase_12 AC 48 ms
63,128 KB
testcase_13 AC 51 ms
63,348 KB
testcase_14 AC 51 ms
65,264 KB
testcase_15 AC 51 ms
64,136 KB
testcase_16 AC 42 ms
58,588 KB
testcase_17 AC 51 ms
64,200 KB
testcase_18 AC 51 ms
62,832 KB
testcase_19 AC 50 ms
64,360 KB
testcase_20 AC 53 ms
62,984 KB
testcase_21 AC 52 ms
65,164 KB
testcase_22 AC 50 ms
62,972 KB
testcase_23 AC 52 ms
65,112 KB
testcase_24 AC 50 ms
64,712 KB
testcase_25 AC 40 ms
59,108 KB
testcase_26 AC 44 ms
61,448 KB
testcase_27 AC 52 ms
65,640 KB
testcase_28 AC 51 ms
65,264 KB
testcase_29 AC 52 ms
64,756 KB
testcase_30 AC 52 ms
64,200 KB
testcase_31 AC 43 ms
60,280 KB
testcase_32 AC 43 ms
60,600 KB
testcase_33 AC 49 ms
64,104 KB
testcase_34 AC 46 ms
62,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import chain, product


def prime_set(N):
    """
    Nまでの素数のsetを返す
    """
    if N < 4:
        return ({}, {}, {2}, {2, 3})[N]
    Nsq = int(N ** 0.5 + 0.5) + 1
    primes = {2, 3} | set(chain(range(5, N + 1, 6), range(7, N + 1, 6)))
    for i in range(5, Nsq, 2):
        if i in primes:
            primes -= set(range(i * i, N + 1, i * 2))
    return primes


M = int(input())
N = int(input())
C = list(map(int, input().split()))
prime = prime_set(M+10)

dp = [-1] * (M + 1)
dp[0] = 0
for c in C:
    for i in range(M):
        if dp[i] == -1:
            continue
        if i + c <= M:
            dp[i + c] = max(dp[i + c], dp[i] + 1)

ans = 0
for cost, buy in enumerate(dp):
    if buy == -1:
        continue
    if M - cost in prime:
        ans += buy
ans += M // min(C)
print(ans)
0