結果

問題 No.385 カップ麺生活
ユーザー ayaoniayaoni
提出日時 2020-12-08 13:46:40
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,307 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 66,704 KB
最終ジャッジ日時 2023-10-17 17:11:51
合計ジャッジ時間 3,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,824 KB
testcase_01 AC 37 ms
53,824 KB
testcase_02 AC 36 ms
53,824 KB
testcase_03 AC 41 ms
60,052 KB
testcase_04 AC 47 ms
62,340 KB
testcase_05 AC 47 ms
60,108 KB
testcase_06 AC 47 ms
62,404 KB
testcase_07 AC 50 ms
64,468 KB
testcase_08 AC 47 ms
62,344 KB
testcase_09 RE -
testcase_10 AC 50 ms
62,552 KB
testcase_11 AC 36 ms
53,824 KB
testcase_12 AC 48 ms
62,344 KB
testcase_13 AC 49 ms
64,472 KB
testcase_14 AC 55 ms
66,704 KB
testcase_15 AC 52 ms
64,488 KB
testcase_16 AC 41 ms
60,140 KB
testcase_17 AC 50 ms
64,464 KB
testcase_18 AC 49 ms
62,352 KB
testcase_19 AC 48 ms
62,352 KB
testcase_20 AC 50 ms
64,472 KB
testcase_21 AC 58 ms
66,548 KB
testcase_22 AC 50 ms
64,468 KB
testcase_23 AC 51 ms
64,476 KB
testcase_24 AC 49 ms
62,404 KB
testcase_25 AC 42 ms
60,044 KB
testcase_26 AC 44 ms
60,184 KB
testcase_27 AC 50 ms
64,476 KB
testcase_28 AC 50 ms
64,476 KB
testcase_29 AC 50 ms
64,484 KB
testcase_30 AC 50 ms
64,464 KB
testcase_31 AC 44 ms
62,200 KB
testcase_32 AC 46 ms
62,328 KB
testcase_33 AC 50 ms
64,468 KB
testcase_34 AC 51 ms
64,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


def sieve_of_eratosthenes(n):  # n以下の素数の全列挙
    prime_list = []
    A = [1]*(n+1)  # A[i] = iが素数なら1,その他は0
    A[0] = A[1] = 0
    for i in range(2,int(n**.5)+1):
        if A[i]:
            prime_list.append(i)
            for j in range(i**2,n+1,i):
                A[j] = 0
    for i in range(int(n**.5)+1,n+1):
        if A[i] == 1:
            prime_list.append(i)
    return prime_list


M,N = I(),I()
C = LI()

price = [-1]*(M+1)  # price[i] = 最大何個のカップ麺でi円を実現できるか(できなければ-1)
price[0] = 0
for i in range(1,M+1):
    for j in range(N):
        c = C[j]
        if i >= c and price[i-c] >= 0:
            price[i] = max(price[i],price[i-c]+1)

prime_list = sieve_of_eratosthenes(M-1)
ans = sum(price[M-p] for p in prime_list if price[M-p] >= 0) + M//min(C)
print(ans)
0