結果

問題 No.385 カップ麺生活
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-01 23:46:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 163,576 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 06:19:27
合計ジャッジ時間 2,725 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

int M, N;
int C[20];
int dp[21][10001];
//-----------------------------------------------------------------
bool isprime(int x) {
	if (x == 2) return true;
	if (x < 1 || x % 2 == 0) return false;

	int i = 3;
	while (i <= sqrt(x)) {
		if (x % i == 0) return false;
		i += 2;
	}

	return true;
}
//-----------------------------------------------------------------
int main() {
	scanf("%d %d", &M, &N);
	rep(i, 0, N) scanf("%d", &C[i]);

	rep(i, 0, N + 1) rep(j, 0, M + 1) dp[i][j] = -1;

	dp[0][M] = 0;
	rep(i, 0, N) rep(j, 0, M + 1) if(0 <= dp[i][j]){
		rep(k, 0, j / C[i] + 1)
			dp[i + 1][j - k * C[i]] = max(dp[i + 1][j - k * C[i]], dp[i][j] + k);
	}

	int ans = 0;
	int _max = 0;
	rep(j, 0, M + 1) if(0 <= dp[N][j]){
		if (isprime(j))
			ans += dp[N][j];
		else
			_max = max(_max, dp[N][j]);
	}
	ans += _max;
	printf("%d\n", ans);
}
0