結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
🍡yurahuna
|
| 提出日時 | 2016-07-01 23:25:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,611 bytes |
| コンパイル時間 | 1,562 ms |
| コンパイル使用メモリ | 172,772 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 22:28:21 |
| 合計ジャッジ時間 | 2,620 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;
// x > 0
bool isPrime(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return n != 1;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int M, N;
cin >> M >> N;
V C(N);
rep(i, N) cin >> C[i];
VV dp(N + 1, V(M + 1, -inf)); // Cの部分和 最大何個で作れるか
dp[0][0] = 0;
rep(i, N) {
rep(j, M + 1) {
if (j < C[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - C[i]] + 1);
}
}
}
// rep(i, N + 1) {
// rep(j, M + 1) {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
int ans = 0;
rep2(i, 1, M) {
// cout << M - i << endl;
if (dp[N][i] > 0 && isPrime(M - i)) {
// cout << M - i << " " << ans << " " << dp[N][M - i] << endl;
ans += dp[N][i];
}
}
ans += *max_element(all(dp[N]));
cout << ans << endl;
}
🍡yurahuna