結果

問題 No.458 異なる素数の和
ユーザー chocopuuchocopuu
提出日時 2018-09-01 10:32:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,148 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 152,660 KB
実行使用メモリ 431,272 KB
最終ジャッジ日時 2023-10-13 10:54:13
合計ジャッジ時間 7,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 180 ms
274,120 KB
testcase_02 AC 214 ms
274,088 KB
testcase_03 AC 149 ms
274,004 KB
testcase_04 WA -
testcase_05 AC 198 ms
277,896 KB
testcase_06 AC 164 ms
277,908 KB
testcase_07 AC 140 ms
289,620 KB
testcase_08 AC 200 ms
318,708 KB
testcase_09 AC 141 ms
364,340 KB
testcase_10 AC 138 ms
363,228 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 139 ms
394,188 KB
testcase_14 AC 140 ms
394,464 KB
testcase_15 AC 139 ms
394,196 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 137 ms
394,320 KB
testcase_20 AC 137 ms
394,272 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 140 ms
394,424 KB
testcase_24 WA -
testcase_25 AC 141 ms
394,236 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0