結果

問題 No.458 異なる素数の和
ユーザー snrnsidysnrnsidy
提出日時 2021-02-21 21:53:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 202,968 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:02:16
合計ジャッジ時間 4,913 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

bool isprime[20001];
vector <int> prime;
int dp[20001];

int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	
	memset(isprime,true,sizeof(isprime));
	
	for(int i=2;i<=20000;i++)
	{
		if(isprime[i])
		{
			prime.push_back(i);
			for(int j=2*i;j<=20000;j+=i)
			{
				isprime[j] = false;
			}
		}
	}
	
	for(int i=0;i<prime.size();i++)
	{
		for(int j=20000;j>=0;j--)
		{
			if(dp[j]==-1)
			{
				continue;
			}
			if(j + prime[i] <= 20000)
			{
				dp[j + prime[i]] = max(dp[j + prime[i]],dp[j] + 1);
			}
		}
	}
	
	int n;
	cin >> n;
	
	cout << dp[n] << '\n';
	
	return 0;
}
0