結果

問題 No.458 異なる素数の和
ユーザー hokutohokuto
提出日時 2021-09-05 19:35:22
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 5,708 ms
コンパイル使用メモリ 108,072 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 05:29:09
合計ジャッジ時間 3,367 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
using namespace std;
using ll = long long int;
#define chmax(x,y)  (x) = ((x) > (y)) ? (x) : ((x) = (y));
#define chmin(x,y)  (x) = ((x) < (y)) ? (x) : ((x) = (y));


int main(int argc, char const *argv[])
{
  int N; cin >> N;
  vector<int> prime;
  auto eratos = [&](int x)
  {
    vector<int> v(x+1,1);
    v[0] = v[1] = 0;
    for(int i=2;i*i<=x;++i)
    {
      if(v[i])
      {
        //std::cout << i << std::endl;
        for(int j=i*i;j<=x;j+=i)
        {
          v[j] = 0;
        }
      }
    }
    for(int i=2;i<=x;++i)
    {
      if(v[i])prime.push_back(i);
    }
  };
  eratos(N);
  vector<int> dp(N+2,-1);
  dp[0] = 0;
  for(auto &p : prime)for(int i=N;i>=0;--i)
  {
    if(dp[i] != -1 && i+p <= N)chmax(dp[i+p],dp[i]+1);
  }
  std::cout << dp[N] << std::endl;
}
0