結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-28 03:29:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 880 bytes |
| コンパイル時間 | 149 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 66,176 KB |
| 最終ジャッジ日時 | 2024-09-28 09:50:43 |
| 合計ジャッジ時間 | 3,103 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
## https://yukicoder.me/problems/no/385
def main():
M = int(input())
N = int(input())
C = list(map(int, input().split()))
dp = [-1] * (M + 1)
dp[M] = 0
for m in reversed(range(M + 1)):
if dp[m] == -1:
continue
for c in C:
if m - c >= 0:
dp[m - c] = max(dp[m - c], dp[m] + 1)
# 素数列挙
primes = []
primes_flags = [True] * (M + 1)
primes_flags[0] = False
primes_flags[1] = False
for p in range(2, M):
if not primes_flags[p]:
continue
primes.append(p)
x = 2 * p
while x <= M:
primes_flags[x] = False
x += p
primes.reverse()
answer = 0
for p in primes:
if dp[p] != -1:
answer += dp[p]
answer += max(dp)
print(answer)
if __name__ == "__main__":
main()