結果
問題 |
No.385 カップ麺生活
|
ユーザー |
![]() |
提出日時 | 2025-02-06 00:48:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 652 bytes |
コンパイル時間 | 3,244 ms |
コンパイル使用メモリ | 81,996 KB |
実行使用メモリ | 67,584 KB |
最終ジャッジ日時 | 2025-02-06 00:48:46 |
合計ジャッジ時間 | 6,549 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
def PrimeList(N): P = [1] * (N + 1) P[0] = P[1] = 0 for i in range(2, N + 1): if P[i]: for j in range(i + i, N + 1, i): P[j] = 0 PL = [] for i in range(N + 1): if P[i] == 1: PL.append(i) return PL M = int(input()) N = int(input()) C = list(map(int, input().split())) PL = PrimeList(M) PLS = set(PL) dp = [-1] * (M + 1) dp[M] = 0 for c in C: for i in reversed(range(c, M + 1)): if dp[i] != -1: dp[i - c] = max(dp[i - c], dp[i] + 1) maxv = max(dp) ans = maxv for i in range(M + 1): if i in PLS and dp[i] != -1: ans += dp[i] print(ans)