結果

問題 No.458 異なる素数の和
ユーザー shop_oneshop_one
提出日時 2019-08-06 17:44:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 884 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 73,200 KB
実行使用メモリ 179,992 KB
最終ジャッジ日時 2023-09-25 17:56:52
合計ジャッジ時間 4,070 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,580 KB
testcase_01 AC 101 ms
93,828 KB
testcase_02 AC 112 ms
107,776 KB
testcase_03 AC 42 ms
43,408 KB
testcase_04 AC 48 ms
49,644 KB
testcase_05 AC 179 ms
163,252 KB
testcase_06 AC 109 ms
104,644 KB
testcase_07 AC 8 ms
9,552 KB
testcase_08 AC 180 ms
164,096 KB
testcase_09 AC 21 ms
24,088 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 205 ms
179,992 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 32 ms
32,820 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,480 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 106 ms
101,736 KB
testcase_28 AC 195 ms
178,068 KB
testcase_29 AC 14 ms
17,276 KB
testcase_30 AC 79 ms
79,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#define FALSE -1
using namespace std;
vector<int> n_list;
void eratos(bool cp_list[],int max){
  for(int i=2;i<=max;i++){
    cp_list[i]=true;
  }
  cp_list[1]=false;
  for(int i=2;i<=max;i++){
    if(cp_list[i]){
      n_list.push_back(i);
      for(int j=i+i;j<=max;j+=i){
        cp_list[j]=false;
      }
    }
  }
}
int main(){
  int s=0,e=0,ans=-1,size,num=0,n;
  bool b[20001];
  cin >> n;
  eratos(b,20000);
  size=n_list.size();
  vector<vector<int>> dp(size,vector<int>(n+1,-1));
  for(int i=0;i<size;i++){
    dp[i][0]=0;
  }
  dp[0][n_list[0]]=1;
  for(int i=1;i<size;i++){
    for(int j=0;j<=n;j++){
      dp[i][j]=dp[i-1][j];
      if(j-n_list[i]>=0&&dp[i-1][j-n_list[i]]!=FALSE){
        dp[i][j]=max(dp[i][j],dp[i-1][j-n_list[i]]+1);
      }
    }
  }
  if(dp[size-1][n]==FALSE) cout <<"-1\n";
  else cout << dp[size-1][n]<<endl;
}
0