結果

問題 No.458 異なる素数の和
ユーザー tomoishtomoish
提出日時 2020-01-07 17:58:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 2,407 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 167,908 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 23:24:29
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


bool is_prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return n!=1;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;


    ll n;
    vll v;
    cin>>n;
    rep2(i,1,n+1){
        if(is_prime(i)) v.pb(i);
    }
    ll dp[20010]={};
    ll m=v.size();
    dp[2]=1;
    rep2(i,1,m){

        repr(j,n+1){
            if(dp[j]>0&&j+v[i]<=n){
                chmax(dp[j+v[i]],dp[j]+1);
            }
        }
        chmax(dp[v[i]],1ll);
    }
    if(dp[n]==0) cout<<-1<<endl;
    else cout<<dp[n]<<endl;
    // rep(i,n+1) cout<<dp[i]<<endl;
    return 0;
}
0