結果

問題 No.458 異なる素数の和
ユーザー eQeeQe
提出日時 2020-03-27 06:37:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 4,556 ms
コンパイル使用メモリ 146,236 KB
実行使用メモリ 374,064 KB
最終ジャッジ日時 2023-08-30 16:07:24
合計ジャッジ時間 4,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
13,720 KB
testcase_01 AC 108 ms
144,820 KB
testcase_02 AC 125 ms
185,268 KB
testcase_03 AC 31 ms
103,748 KB
testcase_04 AC 37 ms
106,100 KB
testcase_05 AC 309 ms
322,156 KB
testcase_06 AC 119 ms
177,656 KB
testcase_07 AC 6 ms
24,264 KB
testcase_08 AC 292 ms
323,804 KB
testcase_09 AC 16 ms
63,028 KB
testcase_10 AC 1 ms
4,356 KB
testcase_11 AC 317 ms
374,064 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,356 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 23 ms
83,736 KB
testcase_17 AC 2 ms
5,652 KB
testcase_18 AC 2 ms
5,564 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 3 ms
7,692 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,356 KB
testcase_23 AC 2 ms
7,696 KB
testcase_24 AC 2 ms
7,664 KB
testcase_25 AC 2 ms
5,452 KB
testcase_26 AC 2 ms
5,504 KB
testcase_27 AC 107 ms
176,228 KB
testcase_28 AC 312 ms
367,520 KB
testcase_29 AC 12 ms
46,852 KB
testcase_30 AC 72 ms
141,548 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);
}

ll dp[2333][22222];

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


0