結果

問題 No.458 異なる素数の和
ユーザー ふっぴーふっぴー
提出日時 2017-05-09 10:42:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 169,248 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 21:43:03
合計ジャッジ時間 3,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846

int main(){
  int n,i,j;
  cin>>n;
  vi sosuu;
  vi moto(n+1);
  loop(i,0,n+1){
    moto[i]=i;
  }
  moto[0]=moto[1]=-1;
  loop(i,2,n+1){
    if(moto[i]!=-1){
      bool flag=false;
      loop(j,2,sqrt(i+1)){
	if(i%j==0){
	  flag=true;
	  break;
	}
      }
      if(flag==false){
	sosuu.push_back(i);
	loop(j,1,n/i+1){
	  moto[i*j]=-1;
	}
      }
    }
  }
  vector<int> dp(n+1,-1);
  dp[0]=0;
  loop(i,0,sosuu.size()){
    rloop(j,n-sosuu[i],0){
      if(dp[j]!=-1){
	dp[j+sosuu[i]]=max(dp[j+sosuu[i]],dp[j]+1);
      }
    }
  }
  cout<<dp[n]<<endl;
}
0