結果

問題 No.458 異なる素数の和
ユーザー shoshoshoshoshosho
提出日時 2020-02-15 10:42:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 1,749 ms
コンパイル使用メモリ 167,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 03:08:39
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;

  bool is_prime[n+1];CLR(is_prime,true);
  is_prime[0]=is_prime[1]=false;

  vector<ll>prime;
  for(ll i=2;i<=n;i++){
    if(is_prime[i]){
      prime.push_back(i);
      for(ll j=2;i*j<=n;j++){
        is_prime[i*j]=false;
      }
    }
  }

  ll dp[20002];
  CLR(dp,-1);
  dp[0]=0;
  rep(i,0,prime.size()){
    for(ll j=n;j>=prime[i];j--){
      if(dp[j-prime[i]]!=-1)chmax(dp[j],dp[j-prime[i]]+1);
    }
  }
  out(dp[n]);

  return 0;
}
0