結果

問題 No.385 カップ麺生活
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-23 02:51:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 750 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 76,928 KB
最終ジャッジ日時 2024-04-19 07:21:32
合計ジャッジ時間 8,331 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
59,136 KB
testcase_01 AC 54 ms
59,392 KB
testcase_02 AC 52 ms
59,008 KB
testcase_03 AC 57 ms
61,184 KB
testcase_04 AC 117 ms
76,160 KB
testcase_05 AC 61 ms
61,696 KB
testcase_06 AC 152 ms
76,544 KB
testcase_07 AC 149 ms
76,544 KB
testcase_08 AC 106 ms
76,288 KB
testcase_09 AC 50 ms
58,496 KB
testcase_10 AC 750 ms
76,928 KB
testcase_11 AC 47 ms
58,112 KB
testcase_12 AC 131 ms
76,416 KB
testcase_13 AC 283 ms
76,672 KB
testcase_14 AC 470 ms
76,672 KB
testcase_15 AC 248 ms
76,416 KB
testcase_16 AC 59 ms
64,128 KB
testcase_17 AC 469 ms
76,544 KB
testcase_18 AC 106 ms
76,160 KB
testcase_19 AC 96 ms
76,672 KB
testcase_20 AC 222 ms
76,544 KB
testcase_21 AC 445 ms
76,928 KB
testcase_22 AC 257 ms
76,672 KB
testcase_23 AC 443 ms
76,928 KB
testcase_24 AC 318 ms
76,800 KB
testcase_25 AC 62 ms
63,488 KB
testcase_26 AC 83 ms
76,672 KB
testcase_27 AC 189 ms
76,544 KB
testcase_28 AC 174 ms
76,672 KB
testcase_29 AC 124 ms
76,544 KB
testcase_30 AC 379 ms
76,800 KB
testcase_31 AC 61 ms
62,208 KB
testcase_32 AC 86 ms
73,856 KB
testcase_33 AC 393 ms
76,544 KB
testcase_34 AC 101 ms
76,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def sieve(n):
    ass = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(math.sqrt(n))+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            ass.append(i)
    return ass

m = int(input())
n = int(input())
C = list(map(int, input().split()))

P = sieve(10**4+1)
ans = 0
for p in P:
    if p < m:
        dp = [-1]*(m-p+1)
        dp[0] = 0
        for i in range(m-p+1):
            if dp[i] != -1:
                for c in C:
                    if i+c <= m-p:
                        dp[i+c] = max(dp[i+c], dp[i]+1)
        if dp[-1] != -1:
            ans += dp[-1]
    else:
        break

dp = [-1]*(m+1)
dp[0] = 0
for i in range(m+1):
    if dp[i] != -1:
        for c in C:
            if i+c <= m:
                dp[i+c] = max(dp[i+c], dp[i]+1)
ans += max(dp)
print(ans)
0