結果

問題 No.458 異なる素数の和
ユーザー dnishdnish
提出日時 2017-07-12 01:13:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 596 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 163,936 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 17:06:27
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
#define p(s) cout<<(s)<<endl
using namespace std;

int dp[20010];
bool isprime[20010];
void make_prime(int N){
	for(int i=2;i*i<=N;i++){
		if(!isprime[i]) continue;
		for(int j=2*i;j<=N;j+=i){
			isprime[j]=false;
		}
	}
}
int main(){
	int N;
	cin>>N;

	REP(i,1,N+1) dp[i]=-1;
	REP(i,2,N+1) isprime[i]=true;
	make_prime(N);
	dp[0]=0;
	REP(i,2,N+1){
		if(isprime[i]){
			RREP(j,0,N-i+1){
				if(dp[j]==-1) continue;
				dp[j+i]=max(dp[j+i],dp[j]+1);
			}
		}
	}
	p(dp[N]);
}
0