結果
問題 | 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/385def main():M = int(input())N = int(input())C = list(map(int, input().split()))dp = [-1] * (M + 1)dp[M] = 0for m in reversed(range(M + 1)):if dp[m] == -1:continuefor 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] = Falseprimes_flags[1] = Falsefor p in range(2, M):if not primes_flags[p]:continueprimes.append(p)x = 2 * pwhile x <= M:primes_flags[x] = Falsex += pprimes.reverse()answer = 0for p in primes:if dp[p] != -1:answer += dp[p]answer += max(dp)print(answer)if __name__ == "__main__":main()