結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
femto
|
| 提出日時 | 2016-07-01 23:14:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 964 bytes |
| コンパイル時間 | 600 ms |
| コンパイル使用メモリ | 69,464 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 22:27:12 |
| 合計ジャッジ時間 | 1,340 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;
const int INF = 1000000;
int dp[20000];
vector<int> sieve_of_eratosthenes(int n) {
vector<int> primes(n);
for(int i = 2; i < n; ++i)
primes[i] = i;
for(int i = 2; i*i < n; ++i)
if(primes[i])
for(int j = i*i; j < n; j += i)
primes[j] = 0;
return primes;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int M, N;
cin >> M >> N;
fill(dp, dp + M + 1000, -INF);
dp[0] = 0;
int C[20];
for(int i = 0; i < N; i++) {
cin >> C[i];
for(int j = 0; j + C[i] <= M; j++) {
if(dp[j] != -INF)
dp[j + C[i]] = max(dp[j + C[i]], dp[j] + 1);
}
}
vector<int> ps = sieve_of_eratosthenes(M + 100);
ll ans = 0;
for(int i = 1; i < M; i++) {
int rem = M - i;
if(ps[rem] && dp[i] != -INF) {
ans += dp[i];
}
}
ans += *max_element(dp, dp + M + 1);
cout << ans << endl;
}
femto