結果

問題 No.458 異なる素数の和
ユーザー yukkuriesuyukkuriesu
提出日時 2018-08-17 11:02:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 160,416 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 22:08:18
合計ジャッジ時間 2,836 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 17 ms
5,376 KB
testcase_02 AC 23 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 51 ms
5,376 KB
testcase_06 AC 22 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 48 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 62 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 4 ms
5,376 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 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 22 ms
5,376 KB
testcase_28 AC 59 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 14 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) cout<<#x<<"="<<x<<endl
#define debugarr(arr,N,M){rep(i,N+1){rep(j,M+1){if(arr[i][j]==INF)printf(" INF");\
	else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};
//--------------------------------------//
int n;
vector<int> primes;
bool isPrime[20001];
int dp[20001];

int main(){
	cin>>n;
	memset(isPrime,1,n+1);
	isPrime[0]=isPrime[1]=false;
	repds(i,1,n){
		if(isPrime[i]){
			primes.pb(i);
			for(int j=i;j<n+1;j+=i) isPrime[j]=false;
		}
	}
	rep(i,n+1)
		rep(j,primes.size()+1){
			if(i==0)dp[i]=0;
			else dp[i]=-1;
		}
	for(auto p:primes)
		for(int i=n;i>0;i--){
			if(i-p>=0&&dp[i-p]!=-1){
				chmax(dp[i],dp[i-p]+1);
			}
		}
	cout<<dp[n]<<endl;
	return 0;
}
0