結果

問題 No.385 カップ麺生活
ユーザー roarisroaris
提出日時 2019-12-11 20:21:00
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 943 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 87,364 KB
実行使用メモリ 102,908 KB
最終ジャッジ日時 2023-09-06 13:09:40
合計ジャッジ時間 9,095 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
75,924 KB
testcase_01 RE -
testcase_02 AC 73 ms
76,044 KB
testcase_03 AC 81 ms
76,580 KB
testcase_04 AC 410 ms
76,724 KB
testcase_05 AC 80 ms
76,596 KB
testcase_06 AC 1,754 ms
78,272 KB
testcase_07 AC 1,453 ms
77,528 KB
testcase_08 AC 298 ms
76,644 KB
testcase_09 RE -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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]]
    
def bellman_ford():
    dist = [10**18]*(M+1)
    dist[M] = 0
    
    for i in range(M):
        for s, t, w in edges:
            if dist[s]!=10**18 and dist[t]>dist[s]+w:
                dist[t] = dist[s]+w
    
    return dist

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

for i in range(M, -1, -1):
    for Ci in C:
        if i-Ci>=0:
            edges.append((i, i-Ci, -1))

dist = bellman_ford()
ans = 0

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

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

print(ans)
0