結果

問題 No.458 異なる素数の和
ユーザー めうめう🎒めうめう🎒
提出日時 2017-02-03 18:22:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,177 ms / 2,000 ms
コード長 1,330 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 76,144 KB
実行使用メモリ 198,988 KB
最終ジャッジ日時 2023-08-25 18:27:55
合計ジャッジ時間 11,085 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
198,988 KB
testcase_01 AC 511 ms
198,788 KB
testcase_02 AC 587 ms
198,824 KB
testcase_03 AC 239 ms
198,784 KB
testcase_04 AC 277 ms
198,784 KB
testcase_05 AC 970 ms
198,764 KB
testcase_06 AC 545 ms
198,792 KB
testcase_07 AC 83 ms
198,796 KB
testcase_08 AC 945 ms
198,784 KB
testcase_09 AC 152 ms
198,956 KB
testcase_10 AC 53 ms
198,792 KB
testcase_11 AC 1,177 ms
198,828 KB
testcase_12 AC 53 ms
198,804 KB
testcase_13 AC 53 ms
198,768 KB
testcase_14 AC 53 ms
198,756 KB
testcase_15 AC 52 ms
198,780 KB
testcase_16 AC 189 ms
198,872 KB
testcase_17 AC 55 ms
198,792 KB
testcase_18 AC 55 ms
198,984 KB
testcase_19 AC 52 ms
198,780 KB
testcase_20 AC 56 ms
198,792 KB
testcase_21 AC 54 ms
198,792 KB
testcase_22 AC 54 ms
198,780 KB
testcase_23 AC 57 ms
198,812 KB
testcase_24 AC 56 ms
198,796 KB
testcase_25 AC 54 ms
198,788 KB
testcase_26 AC 55 ms
198,780 KB
testcase_27 AC 557 ms
198,784 KB
testcase_28 AC 1,059 ms
198,828 KB
testcase_29 AC 125 ms
198,784 KB
testcase_30 AC 411 ms
198,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int memo[2500][20000] = {};
vector<int> sosu;
int n;

bool isSosu(int a){
	for(int i = 2;i * i <= a;i++){
		if(a % i == 0) return false;
	}
	return true;
}

void init(){
	bool used[20010] = {};
	for(int i = 2;i < 20010;i++){
		if(used[i]) continue;
		if(isSosu(i)){
			sosu.push_back(i);
			for(int j = i;j < 20010;j *= 2){
				used[j] = true;
			}
		}
	}
	memset(memo, -1, sizeof(memo));
}
//2500*20000
int saiki(int index, int now){
	if(now == n) return 0;
	else if(now > n || index >= sosu.size()) return -INF;

	if(memo[index][now] != -1) return memo[index][now];

	int a, b;
	a = saiki(index + 1, now + sosu[index]) + 1;
	b = saiki(index + 1, now);

	return memo[index][now] = max(a, b);
}

int main() {
	init();
	// cout << sosu.size() << endl;
	cin >> n;
	// for(int i = 0;i < 10;i++){
	// 	cout << sosu[i] << " ";
	// }
	int ans = saiki(0, 0);

	if(ans < 0) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}
0