結果
問題 | No.385 カップ麺生活 |
ユーザー |
![]() |
提出日時 | 2016-12-06 17:29:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 2,014 bytes |
コンパイル時間 | 1,604 ms |
コンパイル使用メモリ | 172,936 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 22:53:00 |
合計ジャッジ時間 | 2,569 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h>using namespace std;using pii = pair<int,int>;using ll = long long;#define rep(i, j) for(int i=0; i < (int)(j); i++)#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)#define all(v) v.begin(),v.end()#define debug(x) cerr << #x << " : " << x << endltemplate<class T> bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; }template<class T> bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; }// vectortemplate<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }// pairtemplate<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }const int INF = 1 << 30;const ll INFL = 1LL << 60;class Solver {public:vector<bool> primes(int M) {vector<bool> is_prime(M + 1, true);is_prime[0] = is_prime[1] = false;for(int i = 2; i < is_prime.size(); i++) {if(is_prime[i]) {for(int j = i * 2; j < is_prime.size(); j += i) is_prime[j] = false;}}return is_prime;}bool solve() {int M, N; cin >> M >> N;vector<int> C(N); cin >> C;vector<ll> dp(M + 1, -1);dp[M] = 0;for(int m = M; m >= 0; m--) {for(int c : C) {if(dp[m] >= 0 and m - c >= 0) set_max(dp[m - c], dp[m] + 1);}}auto is_prime = primes(M);ll ans = 0;rep(i, M + 1) {if(is_prime[i] and dp[i] >= 0) {ans += dp[i];}}ll a = *max_element(all(dp));if(a >= 0) ans += a;cout << ans << endl;return 0;}};int main() {cin.tie(0);ios::sync_with_stdio(false);Solver s;s.solve();return 0;}