結果

問題 No.458 異なる素数の和
ユーザー nuxxppnuxxpp
提出日時 2019-11-19 23:42:17
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,366 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 85,776 KB
実行使用メモリ 814,080 KB
最終ジャッジ日時 2024-04-15 03:47:11
合計ジャッジ時間 3,833 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int sieve(int)’:
main.cpp:52:1: warning: no return statement in function returning non-void [-Wreturn-type]
   52 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#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 FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int dp[20005];

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

int sieve(int n) {
  int p = 0;
  for(int i=0; i<=n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;

  for(int i=2; i<=n; i++) {
    if(is_prime[i]) {
      prime.push_back(i);
      for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  sieve(n);

  REP(i, n + 1) dp[i] = -1;
  dp[0] = 0;

  for(auto p: prime) {
    for(int j=n; j>=0; j--) {
      if(p + j <= n && dp[j] != -1) {
        dp[p + j] = max(dp[p + j], dp[j] + 1);
      }
    }
  }

  cout << dp[n] << endl;
}
0