結果
問題 |
No.458 異なる素数の和
|
ユーザー |
![]() |
提出日時 | 2018-09-01 10:32:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,148 bytes |
コンパイル時間 | 1,428 ms |
コンパイル使用メモリ | 168,404 KB |
実行使用メモリ | 298,480 KB |
最終ジャッジ日時 | 2024-09-15 07:56:27 |
合計ジャッジ時間 | 8,297 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 14 WA * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,s,n) for(int i = s;i<n;i++) #define repe(i,s,n) for(int i = s;i<=n;i++) #define pb push_back #define fi first #define se second typedef long long ll; typedef pair<int,int>pint; typedef vector<int>vint; typedef vector<pint>vpint; static const ll maxLL = (ll)1 << 62; const int mod=1000000007; int dy[]={-1,0,1,0}; int dx[]={0,1,0,-1}; //#define int ll int n,m; int dp[3010][40101]; vector<int> P; void make_primes(int n) { vector<bool> primes; primes.resize(n + 1, true); primes[0] = primes[1] = false; rep(i, 2, sqrt(n)) if (primes[i]) for (int j = 0; i * (j + 2) < n; j++) primes[i * (j + 2)] = false; rep(i, 2, n + 1) if (primes[i]) P.push_back(i); } signed main(){ cin>>n; make_primes(n+1); rep(i,0,3010)rep(j,0,20101)dp[i][j]=-1; dp[0][0]=0; rep(i,0,P.size())rep(j,0,n+1){ if(j<P[i])dp[i+1][j]=max(dp[i+1][j],dp[i][j]); else dp[i+1][j]=max(dp[i][j-P[i]]+1,dp[i+1][j]); } int ans=-1; rep(i,0,P.size()){ ans=max(ans,dp[i][n]); } if(ans)cout<<ans<<endl; else cout<<"-1"<<endl; return 0; }