結果

問題 No.458 異なる素数の和
ユーザー hondohondo
提出日時 2020-12-06 22:33:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 172,868 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 15:39:12
合計ジャッジ時間 3,270 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 12 ms
4,348 KB
testcase_02 AC 15 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 31 ms
4,348 KB
testcase_06 AC 15 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 31 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 37 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 14 ms
4,348 KB
testcase_28 AC 36 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 9 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ' ';  } return os;  }


vector<ll> prime(int n) {
  vector<bool> ok(n+1, true);
  ok[0] = ok[1] = false;
  for (int i=1; i*i<=n; i++) {
    if (!ok[i]) continue;

    for (int j=i*2; j<=n; j+=i) {
      ok[j] = false;
    }
  }

  vector<ll> ret;
  for (int i=2; i<=n; i++)
    if (ok[i]) ret.push_back(i);
  return ret;
}


int main() {
  int n; cin >> n;
  auto P = prime(n);
  vector<ll> dp(n+1, -1);
  dp[0] = 0;
  // cout << dp << endl;
  for (auto p: P) {
    // cout << p << endl;
    for (int i=n; i>=0; i--) {
      if (dp[i]==-1) continue;
      if (i+p<=n) {
        chmax(dp[i+p], dp[i] + 1);
        // cout << "\t" << i << "\t" << dp << endl;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
0