結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
T1610
|
| 提出日時 | 2020-07-13 11:39:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,321 bytes |
| コンパイル時間 | 1,810 ms |
| コンパイル使用メモリ | 172,696 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 23:03:37 |
| 合計ジャッジ時間 | 2,615 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}
// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x)
#define dumpL(x)
#define LINE
#define LINEL
#define dumpV(v)
#define dumpVL(v)
#define STOP assert(false)
#endif
#define mp make_pair
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
out << '(' << a.fi << ", " << a.se << ')';
return out;
}
}
struct Sieve {
vector<int> primes;
vector<int> _isPrime;
Sieve(int n) : _isPrime(n+1, 1) {
buildPrimes();
}
void buildPrimes() {
_isPrime[0] = _isPrime[1] = 0;
int n = _isPrime.size();
REP(i, 2, n) {
if(_isPrime[i]) {
primes.push_back(i);
for(int j = i+i; j < n; j += i) _isPrime[j] = false;
}
}
}
bool isPrime(int i) {
return _isPrime[i];
}
};
int main(){
ll m, n;
cin >> m >> n;
vl c(n);
rep(i, n) cin >> c[i];
vl dp(m+1, 0LL);
for(auto&& x: c) if(x < (int)dp.size()) dp[x] = 1;
rep(i, n) {
rep(j, dp.size() - c[i]) if(dp[j] > 0) {
chmax(dp[j+c[i]], dp[j]+1);
}
}
Sieve sieve(m);
ll ans = *max_element(all(dp));
rep(i, m) if(sieve.isPrime(m - i)) {
ans += dp[i];
dump(i);dumpL(dp[i]);
}
cout << ans << '\n';
dumpL(dp[m]);
return 0;
}
T1610