結果
| 問題 |
No.458 異なる素数の和
|
| コンテスト | |
| ユーザー |
chaemon
|
| 提出日時 | 2016-12-09 00:27:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 570 ms / 2,000 ms |
| コード長 | 2,278 bytes |
| コンパイル時間 | 743 ms |
| コンパイル使用メモリ | 92,376 KB |
| 実行使用メモリ | 183,424 KB |
| 最終ジャッジ日時 | 2024-07-05 05:37:01 |
| 合計ジャッジ時間 | 18,749 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define EXIST(e,s) ((s).find(e)!=(s).end())
#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;
const int INF=0x3f3f3f3f;
typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif
typedef pair<int,int> pii;
/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}
const int SZ=20000;
int pdiv[SZ];
//{{{ eratosthenes
void sieve_of_eratosthenes(int n) {
for (int i = 2; i < n; ++i)
pdiv[i] = i;
for (int i = 2; i*i < n; ++i)
if (pdiv[i]==i)
for (int j = i*i; j < n; j+=i)
pdiv[j] = i;
}
//}}}
int N;
int dp[20010][2300];
int ans[20010];
vector<int> primes;
int main(){
sieve_of_eratosthenes(SZ);
RREP(i,2,SZ)if(i==pdiv[i])primes.push_back(i);
cin>>N;
for(int n=0;n<=20000;n++){
if(n==0){
dp[n][0] = 0;
}else{
dp[n][0] = -INF;
}
ans[n] = dp[n][0];
for(int i=0;i<primes.size();i++){
dp[n][i+1] = dp[n][i];
int t = n-primes[i];
if(t<0)continue;
if(dp[t][i]>=0){
dp[n][i+1] = max(dp[t][i]+1,dp[n][i+1]);
}
ans[n] = max(ans[n],dp[n][i+1]);
}
}
if(ans[N]<0){
cout<<-1<<endl;
}else{
cout<<ans[N]<<endl;
}
return 0;
}
chaemon