結果

問題 No.458 異なる素数の和
ユーザー polylogKpolylogK
提出日時 2017-09-12 00:35:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 80,336 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-04-25 05:53:00
合計ジャッジ時間 2,228 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//https://yukicoder.me/problems/no/458
//https://yukicoder.me/submissions/203775
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <string.h>
using namespace std;

const int MAX_N=20000;
int n;
int dp[MAX_N+1]={};
bool p[MAX_N+1];

int main(){
	cin >> n;
	
	fill(p,p+sizeof(p),true);
	p[0]=false; p[1]=false;
	for(int i=3;i<=n;i++) for(int j=0;j*j<=i;j++){
		if(p[j]){
			if(i%j) continue;
			else p[i]=false;
		}
	}
	
	memset(dp,-1,sizeof(dp));
	dp[0]++;
	for(int i=2;i<=n;i++){
		if(p[i]) for(int j=n;j>=0;j--){
			if(j+i<=n && dp[j]!=-1) dp[j+i] = max(dp[j]+1, dp[j+i]);
		}
	}
	
	cout << dp[n] << endl;
	return 0;
}
0