結果

問題 No.458 異なる素数の和
ユーザー 幸せウサギ幸せウサギ
提出日時 2019-04-02 10:46:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 63,076 KB
実行使用メモリ 180,152 KB
最終ジャッジ日時 2023-08-19 10:17:07
合計ジャッジ時間 3,409 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,584 KB
testcase_01 AC 46 ms
82,060 KB
testcase_02 AC 61 ms
94,652 KB
testcase_03 AC 15 ms
50,992 KB
testcase_04 AC 17 ms
57,216 KB
testcase_05 AC 130 ms
161,008 KB
testcase_06 AC 56 ms
91,896 KB
testcase_07 AC 4 ms
11,692 KB
testcase_08 AC 130 ms
162,108 KB
testcase_09 AC 8 ms
30,320 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 148 ms
180,152 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 11 ms
38,616 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,388 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 52 ms
89,232 KB
testcase_28 AC 150 ms
178,388 KB
testcase_29 AC 6 ms
22,064 KB
testcase_30 AC 38 ms
72,640 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