結果

問題 No.458 異なる素数の和
ユーザー yukkuriesuyukkuriesu
提出日時 2018-08-17 10:57:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 160,368 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 21:58:29
合計ジャッジ時間 4,033 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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[2500];
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;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(p + i <= n && dp[i] != -1){
                chmax(dp[p+i], dp[i] + 1);
            }
		}
	//debugarr(dp,n,primes.size());
	cout<<dp[n]<<endl;
	return 0;
}
0