結果
| 問題 | No.458 異なる素数の和 |
| コンテスト | |
| ユーザー |
yukkuriesu
|
| 提出日時 | 2018-08-17 10:58:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,275 bytes |
| コンパイル時間 | 1,660 ms |
| コンパイル使用メモリ | 159,980 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 02:55:45 |
| 合計ジャッジ時間 | 2,566 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 26 WA * 1 RE * 1 |
ソースコード
#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[20000];
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(i-p>=0&&dp[i-p]!=-1)
chmax(dp[i],dp[i-p]+1);
}
//debugarr(dp,n,primes.size());
cout<<dp[n]<<endl;
return 0;
}
yukkuriesu