結果

問題 No.385 カップ麺生活
ユーザー 👑 kmjpkmjp
提出日時 2016-07-01 22:58:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 163,576 KB
実行使用メモリ 8,108 KB
最終ジャッジ日時 2024-04-15 07:27:16
合計ジャッジ時間 2,677 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
8,004 KB
testcase_01 AC 9 ms
7,964 KB
testcase_02 AC 10 ms
7,920 KB
testcase_03 AC 11 ms
8,028 KB
testcase_04 AC 11 ms
7,960 KB
testcase_05 AC 9 ms
7,916 KB
testcase_06 AC 9 ms
8,012 KB
testcase_07 AC 11 ms
7,948 KB
testcase_08 AC 10 ms
7,968 KB
testcase_09 AC 10 ms
7,796 KB
testcase_10 AC 11 ms
7,932 KB
testcase_11 AC 11 ms
7,800 KB
testcase_12 AC 9 ms
7,840 KB
testcase_13 AC 11 ms
8,108 KB
testcase_14 AC 10 ms
7,964 KB
testcase_15 AC 10 ms
8,012 KB
testcase_16 AC 9 ms
7,944 KB
testcase_17 AC 10 ms
7,820 KB
testcase_18 AC 10 ms
8,032 KB
testcase_19 AC 11 ms
7,992 KB
testcase_20 AC 10 ms
7,924 KB
testcase_21 AC 10 ms
8,028 KB
testcase_22 AC 10 ms
8,032 KB
testcase_23 AC 10 ms
7,908 KB
testcase_24 AC 10 ms
7,988 KB
testcase_25 AC 11 ms
7,948 KB
testcase_26 AC 10 ms
7,788 KB
testcase_27 AC 10 ms
7,944 KB
testcase_28 AC 9 ms
8,040 KB
testcase_29 AC 10 ms
7,944 KB
testcase_30 AC 9 ms
7,884 KB
testcase_31 AC 10 ms
7,948 KB
testcase_32 AC 10 ms
7,984 KB
testcase_33 AC 11 ms
8,028 KB
testcase_34 AC 11 ms
7,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int M,N;
int C[21];

const int prime_max = 1000000;
int NP,prime[100000],divp[prime_max];

int dp[101010];


void cprime() {
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		//M[i]=NP;
		prime[NP++]=i;
		for(ll j=1LL*i*i;j>i&&j<prime_max;j+=i) divp[j]=i;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cprime();
	
	cin>>M>>N;
	FOR(i,N) cin>>C[i];
	sort(C,C+N);
	
	memset(dp,0xec,sizeof(dp));
	dp[0]=0;
	FOR(i,N) for(x=0;x+C[i]<=M;x++) dp[x+C[i]] = max(dp[x+C[i]],dp[x]+1);
	
	int ma=0;
	FOR(i,M+1) ma=max(ma,dp[i]);
	for(i=1;i<=M-2;i++) if(divp[M-i]==0 && dp[i]>0) ma += dp[i];
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0