結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
sekiya9311
|
| 提出日時 | 2016-10-19 13:31:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,134 bytes |
| コンパイル時間 | 1,262 ms |
| コンパイル使用メモリ | 120,172 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 22:52:09 |
| 合計ジャッジ時間 | 1,869 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <random>
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cerr << C << endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EB emplace_back
#define FORE(a, b) for (auto &&a : b)
#define FIND(s, n) (s.find(n) != s.end())
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
bool isPrime(int num) {
if (num < 2) return false;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) return false;
}
return true;
}
int M, N;
VI C;
int dp[10010];
//dp[i] = 残りi円になるまでに購入した数の最大
int main(void) {
cin >> M >> N;
C.resize(N);
REP(i, N) cin >> C[i];
REP(i, 10010) dp[i] = -1;
dp[M] = 0;
RREP(i, M + 1) {
REP(j, N) {
if (dp[i] != -1 && i - C[j] >= 0) {
dp[i - C[j]] = max(dp[i] + 1, dp[i - C[j]]);
}
}
}
int ans = 0;
REP(i, M) {
if (dp[i] != -1 && isPrime(i)) ans += dp[i];
}
SORT(C);
// DEBUG(ans)
while (M >= 0) {
ans++;
M -= C[0];
}
cout << --ans << endl;
return 0;
}
sekiya9311