結果

問題 No.385 カップ麺生活
ユーザー rpy3cpprpy3cpp
提出日時 2016-07-01 22:41:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-15 07:26:31
合計ジャッジ時間 2,530 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 32 ms
10,752 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 39 ms
10,880 KB
testcase_07 AC 35 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 113 ms
11,136 KB
testcase_11 AC 30 ms
10,752 KB
testcase_12 AC 34 ms
10,752 KB
testcase_13 AC 43 ms
10,880 KB
testcase_14 AC 47 ms
11,136 KB
testcase_15 AC 40 ms
11,008 KB
testcase_16 AC 31 ms
10,752 KB
testcase_17 AC 58 ms
11,008 KB
testcase_18 AC 34 ms
10,752 KB
testcase_19 AC 32 ms
10,752 KB
testcase_20 AC 41 ms
10,752 KB
testcase_21 AC 44 ms
10,880 KB
testcase_22 AC 47 ms
10,880 KB
testcase_23 AC 43 ms
11,008 KB
testcase_24 AC 45 ms
11,136 KB
testcase_25 AC 30 ms
10,752 KB
testcase_26 AC 31 ms
10,880 KB
testcase_27 AC 35 ms
10,880 KB
testcase_28 AC 34 ms
11,008 KB
testcase_29 AC 34 ms
10,880 KB
testcase_30 AC 41 ms
10,880 KB
testcase_31 AC 30 ms
10,880 KB
testcase_32 AC 31 ms
10,880 KB
testcase_33 AC 52 ms
10,880 KB
testcase_34 AC 32 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

M = int(input())
N = int(input())
Cs = list(map(int, input().split()))


def primes2(limit):
    ''' returns a list of prime numbers upto limit.
    source: Rossetta code: Sieve of Eratosthenes
    http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Odds-only_version_of_the_array_sieve_above
    '''
    if limit < 2: return []
    if limit < 3: return [2]
    lmtbf = (limit - 3) // 2
    buf = [True] * (lmtbf + 1)
    for i in range((int(limit ** 0.5) - 3) // 2 + 1):
        if buf[i]:
            p = i + i + 3
            s = p * (i + 1) + i
            buf[s::p] = [False] * ((lmtbf - s) // p + 1)
    return [2] + [i + i + 3 for i, v in enumerate(buf) if v]


def solve(M, N, Cs):
    ps = primes2(M)
    dp = [0] * (M + 1)
    for c in Cs:
        if c > M:
            continue
        dp[M - c] = max(dp[M - c], 1)
        for m in range(M, c - 1, -1):
            if dp[m]:
                dp[m - c] = max(dp[m - c], dp[m] + 1)
    return max(dp) + sum(dp[p] for p in ps)

print(solve(M, N, Cs))
0