結果

問題 No.385 カップ麺生活
ユーザー hanorverhanorver
提出日時 2016-07-02 00:13:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 619 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-20 06:23:33
合計ジャッジ時間 2,909 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 WA -
testcase_02 AC 25 ms
11,008 KB
testcase_03 AC 26 ms
11,008 KB
testcase_04 AC 30 ms
11,008 KB
testcase_05 AC 26 ms
10,880 KB
testcase_06 AC 55 ms
11,008 KB
testcase_07 AC 46 ms
11,008 KB
testcase_08 AC 40 ms
11,008 KB
testcase_09 WA -
testcase_10 AC 199 ms
11,136 KB
testcase_11 AC 33 ms
11,008 KB
testcase_12 AC 38 ms
11,008 KB
testcase_13 AC 62 ms
11,008 KB
testcase_14 AC 63 ms
11,008 KB
testcase_15 AC 49 ms
10,880 KB
testcase_16 AC 32 ms
11,008 KB
testcase_17 AC 85 ms
11,008 KB
testcase_18 WA -
testcase_19 AC 33 ms
10,880 KB
testcase_20 AC 55 ms
11,008 KB
testcase_21 AC 64 ms
11,008 KB
testcase_22 AC 62 ms
11,008 KB
testcase_23 AC 64 ms
11,008 KB
testcase_24 AC 73 ms
11,008 KB
testcase_25 AC 32 ms
10,880 KB
testcase_26 AC 35 ms
11,008 KB
testcase_27 AC 46 ms
10,880 KB
testcase_28 AC 50 ms
10,880 KB
testcase_29 AC 38 ms
10,880 KB
testcase_30 AC 68 ms
10,880 KB
testcase_31 AC 33 ms
10,880 KB
testcase_32 AC 30 ms
10,880 KB
testcase_33 AC 77 ms
11,008 KB
testcase_34 AC 32 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def is_prime(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

def primes(m):
    for i in range(2, m):
        if is_prime(i):
            yield i


m = int(input())
n = input()
values = list(map(int, input().split()))
dp = [0] * 10001
ans = 0

for i, value in enumerate(values):
    dp[value] += 1

for i, value in enumerate(values):
    for j in range(m + 1):
        if dp[j] > 0 and j + value <= m:
            dp[j + value] = max(dp[j] + 1, dp[j + value])

for prime in primes(m):
    ans += dp[m -  prime]

ans += max(dp)

print(ans)
0