結果

問題 No.458 異なる素数の和
ユーザー CleyLCleyL
提出日時 2021-12-14 09:49:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 260 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 73,752 KB
実行使用メモリ 238,140 KB
最終ジャッジ日時 2023-09-30 17:44:21
合計ジャッジ時間 9,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
237,472 KB
testcase_01 AC 199 ms
237,240 KB
testcase_02 AC 207 ms
237,476 KB
testcase_03 AC 179 ms
237,412 KB
testcase_04 AC 181 ms
237,416 KB
testcase_05 AC 247 ms
237,972 KB
testcase_06 AC 206 ms
237,240 KB
testcase_07 AC 175 ms
237,324 KB
testcase_08 AC 247 ms
238,140 KB
testcase_09 AC 176 ms
237,472 KB
testcase_10 AC 176 ms
237,432 KB
testcase_11 AC 260 ms
237,944 KB
testcase_12 AC 174 ms
237,924 KB
testcase_13 AC 172 ms
237,476 KB
testcase_14 AC 172 ms
237,484 KB
testcase_15 AC 183 ms
237,236 KB
testcase_16 AC 178 ms
237,888 KB
testcase_17 AC 175 ms
237,432 KB
testcase_18 AC 178 ms
237,324 KB
testcase_19 AC 174 ms
237,484 KB
testcase_20 AC 177 ms
237,416 KB
testcase_21 AC 174 ms
237,360 KB
testcase_22 AC 176 ms
237,232 KB
testcase_23 AC 174 ms
237,476 KB
testcase_24 AC 174 ms
237,476 KB
testcase_25 AC 186 ms
237,488 KB
testcase_26 AC 175 ms
237,428 KB
testcase_27 AC 208 ms
237,412 KB
testcase_28 AC 258 ms
237,732 KB
testcase_29 AC 177 ms
237,380 KB
testcase_30 AC 195 ms
237,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
struct SieveEratos{
  vector<int> t;
  SieveEratos(int n):t(n+1,true){
    t[0] = t[1] = 1;
    for(int i = 2; n >= i; i++){
      if(t[i]){
        for(int j = i+i; n >= j; j+=i){
          t[j] = 0;
        }
      }
    }
  }
  bool operator[](int x){return t[x];}
};
vector<vector<int>> dp(3000,vector<int>(20000,-1));
int main(){
  int n;cin>>n;
  SieveEratos A(n+1);
  vector<int> B;
  for(int i = 2; n >= i; i++){
    if(A[i])B.push_back(i);
  }
  dp[0][0] = 0;
  for(int i = 0; B.size() > i; i++){
    for(int j = 0; n >= j; j++){
      if(dp[i][j] == -1)continue;
      if(j+B[i] <= n)dp[i+1][j+B[i]] = max(dp[i+1][j+B[i]],dp[i][j]+1);
      dp[i+1][j] = max(dp[i+1][j],dp[i][j]);

    }
  }
  cout << dp[B.size()][n] << endl;
  
}
0