結果

問題 No.458 異なる素数の和
ユーザー eQeeQe
提出日時 2020-03-27 06:11:24
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 969 bytes
コンパイル時間 3,986 ms
コンパイル使用メモリ 146,516 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-30 16:06:12
合計ジャッジ時間 7,430 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PL;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

vector<ll> ps;

void eratos(ll N) {
  ll isp[N+5];
  memset(isp, 1, sizeof(isp));
  isp[0]=isp[1]=0;
  ll i, j;
  
  for(i=2; i*i<=N; i++) {
    if(isp[i]==0) continue;
    for(j=i+i; j<=N; j+=i)
      isp[j]=0;
  }
  
  for(i=0; i<=N; i++) if(isp[i]) ps.push_back(i);
}



int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll dp[22222];
  eratos(N);
  
  for(i=0; i<=N; i++) dp[i]=-1;
  dp[0]=0;
  for(auto p: ps) {
    for(i=N-1; i>=0; i--) {
      if(dp[i]==-1) continue;
      chmax(dp[i+p], dp[i]+1);
    }
  }
  
  pt(dp[N]);
  
  
}


0