結果

問題 No.458 異なる素数の和
ユーザー mkanmkan
提出日時 2018-05-03 20:32:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 95,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 09:22:41
合計ジャッジ時間 2,954 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 22 ms
4,376 KB
testcase_02 AC 25 ms
4,376 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 40 ms
4,376 KB
testcase_06 AC 24 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 40 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 45 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 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,376 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,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 24 ms
4,376 KB
testcase_28 AC 44 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 18 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

vector<int> prime;
bool is_prime[1000005];
int dp[20005];

void init(){
  rep(i,20005)dp[i]=-1;
  dp[0]=0;
}

void sieve(int n){
  rep(i,n+1)is_prime[i]=true;
  for(int i=2;i<n;i++){
    if(is_prime[i]){
      prime.pb(i);
      for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
    }
  }
}

int main(){
  int n;
  cin>>n;
  init();
  sieve(20005);
  for(auto x : prime){
    for(int j=n;j>=0;j--){
      if(j-x>=0&&dp[j-x]!=-1)dp[j]=max(dp[j],dp[j-x]+1);
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}
0