結果

問題 No.385 カップ麺生活
ユーザー rlangevinrlangevin
提出日時 2023-07-17 13:20:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 81,404 KB
実行使用メモリ 65,852 KB
最終ジャッジ日時 2023-10-18 00:23:15
合計ジャッジ時間 6,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
58,284 KB
testcase_01 AC 43 ms
58,212 KB
testcase_02 AC 43 ms
58,152 KB
testcase_03 AC 49 ms
60,276 KB
testcase_04 AC 60 ms
64,008 KB
testcase_05 AC 50 ms
60,456 KB
testcase_06 AC 56 ms
64,108 KB
testcase_07 AC 60 ms
63,388 KB
testcase_08 AC 55 ms
63,256 KB
testcase_09 AC 45 ms
58,084 KB
testcase_10 AC 54 ms
63,756 KB
testcase_11 AC 89 ms
58,076 KB
testcase_12 AC 117 ms
63,788 KB
testcase_13 AC 119 ms
65,820 KB
testcase_14 AC 117 ms
64,236 KB
testcase_15 AC 116 ms
65,840 KB
testcase_16 AC 103 ms
61,808 KB
testcase_17 AC 115 ms
64,468 KB
testcase_18 AC 120 ms
65,832 KB
testcase_19 AC 118 ms
64,160 KB
testcase_20 AC 118 ms
64,240 KB
testcase_21 AC 118 ms
64,336 KB
testcase_22 AC 116 ms
64,152 KB
testcase_23 AC 116 ms
63,440 KB
testcase_24 AC 75 ms
64,140 KB
testcase_25 AC 55 ms
60,332 KB
testcase_26 AC 50 ms
60,656 KB
testcase_27 AC 80 ms
65,844 KB
testcase_28 AC 59 ms
63,956 KB
testcase_29 AC 57 ms
63,376 KB
testcase_30 AC 58 ms
64,216 KB
testcase_31 AC 50 ms
61,308 KB
testcase_32 AC 54 ms
62,836 KB
testcase_33 AC 62 ms
65,852 KB
testcase_34 AC 78 ms
63,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *

def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return S


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

S = Sieve(10050)

inf = 10 ** 18
pre = [-inf] * (M + 1)
pre[0] = 0
for i in range(N):
    dp = [-inf] * (M + 1)
    for m in range(M + 1):
        dp[m] = pre[m]
        
    for m in range(M + 1):
        if m - C[i] >= 0:
            dp[m] = max(dp[m], dp[m - C[i]] + 1)
            
    dp, pre = pre, dp
    
ans = 0
for m in range(M + 1):
    if M - m in S and pre[m] > 0:
        ans += pre[m]
        
print(ans + M//min(C))
0