結果
問題 | No.458 異なる素数の和 |
ユーザー | Hoi_koro |
提出日時 | 2016-12-13 18:42:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 612 ms / 2,000 ms |
コード長 | 1,654 bytes |
コンパイル時間 | 1,042 ms |
コンパイル使用メモリ | 116,548 KB |
実行使用メモリ | 180,664 KB |
最終ジャッジ日時 | 2023-09-18 15:06:04 |
合計ジャッジ時間 | 5,338 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 154 ms
53,712 KB |
testcase_02 | AC | 206 ms
69,252 KB |
testcase_03 | AC | 26 ms
14,124 KB |
testcase_04 | AC | 35 ms
17,504 KB |
testcase_05 | AC | 502 ms
150,940 KB |
testcase_06 | AC | 193 ms
65,672 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 506 ms
151,996 KB |
testcase_09 | AC | 8 ms
6,416 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 612 ms
180,664 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 1 ms
4,380 KB |
testcase_15 | AC | 1 ms
4,376 KB |
testcase_16 | AC | 14 ms
9,360 KB |
testcase_17 | AC | 1 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,380 KB |
testcase_19 | AC | 2 ms
4,380 KB |
testcase_20 | AC | 1 ms
4,380 KB |
testcase_21 | AC | 2 ms
4,380 KB |
testcase_22 | AC | 1 ms
4,376 KB |
testcase_23 | AC | 2 ms
4,380 KB |
testcase_24 | AC | 2 ms
4,380 KB |
testcase_25 | AC | 2 ms
4,380 KB |
testcase_26 | AC | 1 ms
4,376 KB |
testcase_27 | AC | 173 ms
62,380 KB |
testcase_28 | AC | 596 ms
176,696 KB |
testcase_29 | AC | 5 ms
4,576 KB |
testcase_30 | AC | 110 ms
39,536 KB |
ソースコード
#include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cassert> #include <algorithm> #include <iterator> #include <string> #include <vector> #include <list> #include <deque> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <tuple> #include <queue> #include <stack> #include <functional> #include <utility> #include <complex> #include <bitset> #include <numeric> #include <random> using namespace std; #define REP(i,n) for(int (i)=0; (i)<(n) ;++(i)) #define REPN(i,a,n) FOR((i),(a),(a)+(n)) #define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i)) #define PB push_back #define MP make_pair #define SE second #define FI first #define DBG(a) cerr<<(a)<<endl; #define dump(a) cerr<<#a <<' '<< a <<endl; #define ALL(v) (v).begin(),(v).end() typedef long long LL; typedef pair<LL, LL> PLL; typedef vector<LL> VLL; typedef pair<int,int>PI; typedef vector<int> VI; const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7; void pre(int n,VI &p){ p.push_back(2); FOR(i,3,n+1){ bool f=true; for(int a : p){ if(i%a==0) f=false; } if(f) p.push_back(i); } return ; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; VI p; pre(n,p); vector<VI> dp(n+1,VI(p.size()+1,-1)); fill(ALL(dp[0]),0); FOR(i,2,n+1){ FOR(j,1,p.size()+1){ if(i-p[j-1]<0) dp[i][j]=dp[i][j-1]; else if(dp[i-p[j-1]][j-1]<0)dp[i][j]=dp[i][j-1]; else dp[i][j]=max(dp[i][j-1],dp[i-p[j-1]][j-1]+1); } } cout << dp[n][p.size()]<<endl; return 0; }