結果

問題 No.458 異なる素数の和
ユーザー NrKmDevNrKmDev
提出日時 2020-03-27 15:18:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,378 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 168,432 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 16:25:12
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 23 ms
4,376 KB
testcase_02 AC 27 ms
4,376 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 13 ms
4,380 KB
testcase_05 AC 47 ms
4,380 KB
testcase_06 AC 27 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 45 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 50 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 26 ms
4,380 KB
testcase_28 AC 51 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 19 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド:(典型)dp,dfs,bfs,最短経路,その他
vector<bool> isprime(20010,true);
void eratos(int max_n){
    for(int i=2;i*i<=max_n;i++){
        if(isprime[i]){
            for(int j=2*i;j<=max_n;j+=i){
                isprime[j]=false;
            }
        }
    }
}
int main(){
    int n;cin >> n;
    vector<int> prime;
    eratos(20010);
    for(int i=2;i<=20010;i++){
        if(isprime[i]) prime.push_back(i);
    }
    vi dp(20010,-1);
    dp[0]=0;
    for(auto p:prime){
        for(int j=n;j>=0;j--){
            if(p+j<=n&&dp[j]!=-1){
                chmax(dp[p+j],dp[j]+1);
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}
0