結果

問題 No.385 カップ麺生活
ユーザー roarisroaris
提出日時 2019-12-11 20:57:32
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,133 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 75,112 KB
最終ジャッジ日時 2024-04-15 07:40:34
合計ジャッジ時間 3,452 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,988 KB
testcase_01 RE -
testcase_02 AC 42 ms
54,360 KB
testcase_03 AC 42 ms
55,836 KB
testcase_04 AC 60 ms
68,420 KB
testcase_05 AC 44 ms
54,380 KB
testcase_06 AC 66 ms
70,048 KB
testcase_07 AC 63 ms
69,408 KB
testcase_08 AC 62 ms
67,716 KB
testcase_09 AC 41 ms
54,696 KB
testcase_10 AC 73 ms
75,112 KB
testcase_11 AC 41 ms
55,292 KB
testcase_12 AC 63 ms
69,580 KB
testcase_13 AC 73 ms
73,676 KB
testcase_14 AC 69 ms
74,488 KB
testcase_15 AC 67 ms
71,564 KB
testcase_16 AC 45 ms
60,144 KB
testcase_17 AC 74 ms
74,504 KB
testcase_18 AC 65 ms
70,068 KB
testcase_19 AC 63 ms
69,188 KB
testcase_20 AC 70 ms
72,308 KB
testcase_21 AC 69 ms
72,756 KB
testcase_22 AC 67 ms
71,160 KB
testcase_23 AC 75 ms
74,584 KB
testcase_24 AC 68 ms
73,012 KB
testcase_25 AC 41 ms
54,636 KB
testcase_26 AC 47 ms
62,008 KB
testcase_27 AC 73 ms
74,096 KB
testcase_28 AC 67 ms
71,636 KB
testcase_29 AC 61 ms
69,148 KB
testcase_30 AC 73 ms
74,488 KB
testcase_31 AC 46 ms
61,016 KB
testcase_32 AC 48 ms
62,208 KB
testcase_33 AC 66 ms
71,812 KB
testcase_34 AC 50 ms
64,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque

def era(n):
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        
        for j in range(2*i, n+1, i):
            is_prime[j] = False
    
    return [i for i in range(n+1) if is_prime[i]]
    
M = int(input())
N = int(input())
C = list(map(int, input().split()))

if M==1:
    if min(C)==1:
        print(1)
    else:
        print(0)
    exit()
    
ins = [0]*(M+1)
outs = defaultdict(list)

for i in range(M, -1, -1):
    if i!=M and ins[i]==0:
        continue
    
    for Ci in C:
        if i-Ci>=0:
            ins[i-Ci] += 1
            outs[i].append(i-Ci)

q = deque([M])
dp = [-10**18]*(M+1)
dp[M] = 0

while q:
    v = q.popleft()
    
    for nv in outs[v]:
        dp[nv] = max(dp[nv], dp[v]+1)
        ins[nv] -= 1
        
        if ins[nv]==0:
            q.append(nv)

ans = 0

for pi in era(M-1):
    if dp[pi]==-10**18:
        continue
    
    ans += dp[pi]

minC = min(C)
ans += max(dp[i] for i in range(minC) if dp[i]!=-10**18)

print(ans)
0