結果

問題 No.458 異なる素数の和
ユーザー mfbgjsczmfbgjscz
提出日時 2019-12-08 02:02:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 170,676 KB
実行使用メモリ 365,684 KB
最終ジャッジ日時 2023-08-27 15:00:37
合計ジャッジ時間 5,409 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 115 ms
103,272 KB
testcase_02 AC 141 ms
134,844 KB
testcase_03 AC 26 ms
24,936 KB
testcase_04 WA -
testcase_05 AC 334 ms
302,392 KB
testcase_06 AC 133 ms
127,088 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 322 ms
303,920 KB
testcase_09 AC 9 ms
9,604 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(30) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
bool is_prime(lli x) {
  if(x<2)return false;
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main(){
  lli C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,0,0);
  rep(i,2,N+1)if(is_prime(i))P.pb(i);
  M=P.size();
  DV(dp,lli,M+1,N+1,0);
  rep(i,1,M+1)rep(j,0,N+1){
    dp[i][j]=max(dp[i-1][j],dp[i][j]);
    if(j+P[i-1]<=N)dp[i][j+P[i-1]]=max(dp[i-1][j+P[i-1]],dp[i-1][j]+1);
  }
  rep(i,0,M+1)sum=chmax(sum,dp[i][N]);
  sum--;
  if(!sum)sum=-1;
  Out(sum);
}
0