結果

問題 No.385 カップ麺生活
ユーザー Mr.SpockMr.Spock
提出日時 2020-11-19 00:17:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 169,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 15:19:37
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nax = 1e4 + 7;
vector<int>prime(nax, true);
void is_prime() {
	prime[0] = false;
	prime[1] = false;
	for (int i = 2; i < nax; i++) {
		if (prime[i] && ll(i * i) < nax) {
			for (int j = i * i; j <= nax; j += i) {
				prime[j] = false;
			}
		}
	}
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> m >> n;
	is_prime();
	vector<int>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	vector<int>dp(nax, -1);
	dp[m] = 0;
	for (int rem = m; rem >= 0; rem--) {
		for (int rep = 0; rep < n; rep++) {
			if (rem - v[rep] >= 0 && dp[rem] >= 0) {
				dp[rem - v[rep]] = max(1 + dp[rem], dp[rem - v[rep]]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= m; i++) {
		if (prime[i] && dp[i] != -1) {
			ans += dp[i];
		}
	}
	while (m > 0) {
		if (m - v[0] >= 0) {
			ans++;
		}
		m = m - v[0];
	}
	cout << ans << endl;
}
0