結果

問題 No.385 カップ麺生活
ユーザー roarisroaris
提出日時 2019-12-11 20:54:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,133 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 80,952 KB
最終ジャッジ日時 2023-09-06 13:28:52
合計ジャッジ時間 6,045 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,700 KB
testcase_01 RE -
testcase_02 AC 97 ms
71,876 KB
testcase_03 AC 96 ms
72,252 KB
testcase_04 AC 117 ms
78,280 KB
testcase_05 AC 94 ms
71,892 KB
testcase_06 AC 121 ms
78,216 KB
testcase_07 AC 118 ms
77,960 KB
testcase_08 AC 116 ms
78,380 KB
testcase_09 RE -
testcase_10 AC 114 ms
78,528 KB
testcase_11 AC 84 ms
72,100 KB
testcase_12 AC 107 ms
78,112 KB
testcase_13 AC 116 ms
78,220 KB
testcase_14 AC 104 ms
78,536 KB
testcase_15 AC 105 ms
78,360 KB
testcase_16 AC 88 ms
76,916 KB
testcase_17 AC 110 ms
78,236 KB
testcase_18 AC 102 ms
78,260 KB
testcase_19 AC 100 ms
78,132 KB
testcase_20 AC 103 ms
78,032 KB
testcase_21 AC 110 ms
78,244 KB
testcase_22 AC 103 ms
78,232 KB
testcase_23 AC 108 ms
78,300 KB
testcase_24 AC 104 ms
78,324 KB
testcase_25 AC 82 ms
72,088 KB
testcase_26 AC 87 ms
77,304 KB
testcase_27 AC 112 ms
78,308 KB
testcase_28 AC 106 ms
78,084 KB
testcase_29 AC 102 ms
78,204 KB
testcase_30 AC 110 ms
78,136 KB
testcase_31 AC 89 ms
77,192 KB
testcase_32 AC 90 ms
77,428 KB
testcase_33 AC 101 ms
78,452 KB
testcase_34 AC 91 ms
77,640 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())

if M==1:
    if min(C)==1:
        print(1)
    else:
        print(0)
    exit()
    
N = int(input())
C = list(map(int, input().split()))
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