結果

問題 No.458 異なる素数の和
ユーザー 幸せウサギ幸せウサギ
提出日時 2019-04-02 10:46:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 62,560 KB
実行使用メモリ 180,352 KB
最終ジャッジ日時 2024-05-06 17:31:12
合計ジャッジ時間 2,485 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 46 ms
58,496 KB
testcase_02 AC 47 ms
74,752 KB
testcase_03 AC 15 ms
16,768 KB
testcase_04 AC 18 ms
20,352 KB
testcase_05 AC 98 ms
158,592 KB
testcase_06 AC 42 ms
70,912 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 127 ms
160,128 KB
testcase_09 AC 6 ms
8,064 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 149 ms
180,352 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 10 ms
11,520 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 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 60 ms
67,712 KB
testcase_28 AC 146 ms
178,304 KB
testcase_29 AC 5 ms
5,888 KB
testcase_30 AC 33 ms
43,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int N,M;
int i1[7500]={0};
int dp[7500][20010]={0};
int i,j,k,c=0;
int main(void){
	cin>>N;
	i1[c]=2;
	c++;
	for(i=3;i<=N;i+=2){
		k=0;
		for(j=3;j<=sqrt(i);j+=2)
		{
			if(i%j==0)
			{
				k=1;
				break;
			}
		}
		if(k==0){
			i1[c]=i;
			c++;
		}
	}
	for(j=0;j<c;j++){
		for(i=2;i<=N;i++){
			if((dp[j][i-i1[j]]>0||i1[j]==i)&&i-i1[j]>=0){
				dp[j+1][i]=max(dp[j][i],dp[j][i-i1[j]]+1);
			}
			else{
				dp[j+1][i]=dp[j][i];
			}
		}
	}
	if(dp[c][N]==0){cout<<-1<<endl;;}
	else{cout<<dp[c][N]<<endl;}
	return 0;
}
0