結果

問題 No.385 カップ麺生活
ユーザー kyuridenamidakyuridenamida
提出日時 2016-07-01 22:52:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 160,252 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:26:58
合計ジャッジ時間 2,653 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

#define int long long

int S[1<<20];
int P[10010];
int isp(int n){
	if( n <= 1 ) return false;
	for(int i = 2 ; i * i <= n ; i++)
		if( n % i == 0 ) return false;
	return true;
}


int dp[20010];

vector<int> trans;
signed main(){
	for(int i = 0 ; i <= 10000 ; i++){
		if( P[i] = isp(i) ){
		}
	}
	
	ios_base::sync_with_stdio(false);
	int M;
	int N;
	cin >> M >> N;
	
	for(int i = 0 ; i < 20000 ; i++)
		dp[i] = -1e9;
	dp[0] = 0;
	for(int i = 0 ; i < N ; i++){
		int c;
		cin >> c;
		for(int j = 0 ; j <= 10000 ; j++){
			dp[j+c] = max(dp[j]+1,dp[j+c]);
		}
	}
	int ans = 0;
	int mx = 0;
	for(int i = 0 ; i <= M ; i++){
		if( P[M - i] and dp[i] >= 0 ){
			ans += dp[i];
		}
		mx = max(dp[i],mx);
	}
	cout << ans + mx << endl;
	
	
	
	
}
0