結果

問題 No.385 カップ麺生活
ユーザー lloyzlloyz
提出日時 2023-01-31 00:16:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 86,616 KB
実行使用メモリ 76,528 KB
最終ジャッジ日時 2023-09-12 20:21:41
合計ジャッジ時間 5,769 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
76,176 KB
testcase_01 AC 77 ms
75,952 KB
testcase_02 AC 78 ms
75,940 KB
testcase_03 AC 78 ms
76,276 KB
testcase_04 AC 85 ms
76,172 KB
testcase_05 AC 78 ms
76,268 KB
testcase_06 AC 87 ms
76,116 KB
testcase_07 AC 86 ms
76,372 KB
testcase_08 AC 87 ms
76,116 KB
testcase_09 AC 76 ms
75,964 KB
testcase_10 AC 86 ms
76,180 KB
testcase_11 AC 78 ms
76,164 KB
testcase_12 AC 83 ms
76,528 KB
testcase_13 AC 86 ms
76,200 KB
testcase_14 AC 87 ms
76,500 KB
testcase_15 AC 86 ms
76,500 KB
testcase_16 AC 79 ms
76,360 KB
testcase_17 AC 87 ms
76,320 KB
testcase_18 AC 87 ms
76,384 KB
testcase_19 AC 88 ms
76,384 KB
testcase_20 AC 86 ms
76,408 KB
testcase_21 AC 88 ms
76,420 KB
testcase_22 AC 87 ms
76,052 KB
testcase_23 AC 87 ms
76,328 KB
testcase_24 AC 86 ms
76,048 KB
testcase_25 AC 78 ms
76,088 KB
testcase_26 AC 82 ms
76,032 KB
testcase_27 AC 88 ms
76,296 KB
testcase_28 AC 85 ms
76,100 KB
testcase_29 AC 87 ms
76,288 KB
testcase_30 AC 89 ms
76,204 KB
testcase_31 AC 81 ms
76,376 KB
testcase_32 AC 83 ms
76,068 KB
testcase_33 AC 87 ms
76,292 KB
testcase_34 AC 84 ms
76,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

IsPrime = [True for _ in range(10**4 + 1)]
IsPrime[0] = IsPrime[1] = False
for i in range(2, 10**4 + 1):
    if IsPrime[i]:
        for j in range(i * i, 10**4 + 1, i):
            IsPrime[j] = False

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

DP = [-1 for _ in range(c + 1)]
DP[c] = 0
for i in range(n):
    a = C[i]
    for j in range(c, -1, -1):
        if DP[j] != -1 and j - a >= 0:
            DP[j - a] = max(DP[j - a], DP[j] + 1)
ans = max(DP)
for i in range(c + 1):
    if IsPrime[i] and DP[i] != -1:
        ans += DP[i]
print(ans)
0