結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
yosupot
|
| 提出日時 | 2016-07-01 23:02:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,200 bytes |
| コンパイル時間 | 409 ms |
| コンパイル使用メモリ | 61,440 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-04 22:26:16 |
| 合計ジャッジ時間 | 1,267 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cassert>
using namespace std;
using ll = long long;
constexpr ll TEN(int n) { return (!n) ? 1 : 10 * TEN(n-1); }
int m, n, c[20];
int dp0[10100], dp1[10100];
bool us0[10100], us1[10100];
int dfs(int x) {
if (x < 0) return -100000;
if (x == 0) return 0;
if (us0[x]) return dp0[x];
us0[x] = true;
int ans = -100000;
for (int i = 0; i < n; i++) {
ans = max(ans, 1+dfs(x-c[i]));
}
return dp0[x] = ans;
}
int dfs2(int x) {
if (x < 0) return -100000;
if (x == 0) return 0;
if (us1[x]) return dp1[x];
us1[x] = true;
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, 1+dfs2(x-c[i]));
}
return dp1[x] = ans;
}
int main() {
cin >> m;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int ans = dfs2(m);
for (int i = 2; i < m; i++) {
bool f = true;
for (int j = 2; j*j <= i; j++) {
if (i % j == 0) f = false;
}
if (f) {
ans += max(0, dfs(m-i));
}
}
cout << ans << endl;
return 0;
}
yosupot