結果

問題 No.458 異なる素数の和
ユーザー yukkuriesuyukkuriesu
提出日時 2018-08-17 10:43:16
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,266 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 160,992 KB
実行使用メモリ 22,648 KB
最終ジャッジ日時 2024-04-16 21:24:42
合計ジャッジ時間 6,877 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 3 ms
10,340 KB
testcase_08 RE -
testcase_09 AC 10 ms
22,648 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 RE -
testcase_12 AC 1 ms
6,940 KB
testcase_13 WA -
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 RE -
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 6 ms
18,500 KB
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
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][2500];

int main(){
	cin>>n;
	memset(isPrime,1,n);
	isPrime[0]=isPrime[1]=false;
	repd(i,2,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][j]=0;
			else dp[i][j]=-1;
		}
	reps(i,n)
		reps(j,primes.size()){
			dp[i][j]=dp[i][j-1];
			if(i>=primes[j-1]&&dp[i-primes[j-1]][j-1]!=-1)
				dp[i][j]=max(dp[i][j],dp[i-primes[j-1]][j-1]+1);
		}
//	debugarr(dp,n,primes.size());
	cout<<dp[n][primes.size()]<<endl;
	return 0;
}
0