結果

問題 No.458 異なる素数の和
ユーザー 👑 kmjpkmjp
提出日時 2016-12-09 00:02:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 1,246 ms
コンパイル使用メモリ 147,412 KB
実行使用メモリ 8,552 KB
最終ジャッジ日時 2023-09-18 14:44:42
合計ジャッジ時間 5,198 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
8,304 KB
testcase_01 AC 78 ms
8,320 KB
testcase_02 AC 78 ms
8,336 KB
testcase_03 AC 78 ms
8,368 KB
testcase_04 AC 77 ms
8,364 KB
testcase_05 AC 78 ms
8,392 KB
testcase_06 AC 78 ms
8,320 KB
testcase_07 AC 78 ms
8,416 KB
testcase_08 AC 78 ms
8,364 KB
testcase_09 AC 78 ms
8,364 KB
testcase_10 AC 78 ms
8,316 KB
testcase_11 AC 78 ms
8,480 KB
testcase_12 AC 78 ms
8,352 KB
testcase_13 AC 77 ms
8,396 KB
testcase_14 AC 78 ms
8,364 KB
testcase_15 AC 78 ms
8,480 KB
testcase_16 AC 78 ms
8,352 KB
testcase_17 AC 78 ms
8,308 KB
testcase_18 AC 78 ms
8,308 KB
testcase_19 AC 78 ms
8,320 KB
testcase_20 AC 79 ms
8,552 KB
testcase_21 AC 78 ms
8,416 KB
testcase_22 AC 78 ms
8,416 KB
testcase_23 AC 79 ms
8,420 KB
testcase_24 AC 78 ms
8,416 KB
testcase_25 AC 78 ms
8,416 KB
testcase_26 AC 78 ms
8,320 KB
testcase_27 AC 78 ms
8,404 KB
testcase_28 AC 78 ms
8,460 KB
testcase_29 AC 77 ms
8,300 KB
testcase_30 AC 78 ms
8,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

const int prime_max = 1000000;
int NP,prime[100000],divp[prime_max];
map<int,int> M;

void cprime() {
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		//M[i]=NP;
		prime[NP++]=i;
		for(ll j=1LL*i*i;j>i&&j<prime_max;j+=i) divp[j]=i;
	}
}
int N;
int ma[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cprime();
	MINUS(ma);
	ma[0]=0;
	FOR(i,10000) {
		x=prime[i];
		if(x>20000) break;
		for(j=20000;j>=0;j--) if(ma[j]>=0 && i+x<=200000) ma[j+x]=max(ma[j+x],ma[j]+1);
	}
	
	cin>>N;
	cout<<ma[N]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0