結果
問題 | No.458 異なる素数の和 |
ユーザー | kabbo ghosh |
提出日時 | 2021-08-04 13:47:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,953 bytes |
コンパイル時間 | 2,387 ms |
コンパイル使用メモリ | 209,900 KB |
実行使用メモリ | 180,864 KB |
最終ジャッジ日時 | 2024-09-16 15:08:02 |
合計ジャッジ時間 | 16,534 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 148 ms
180,736 KB |
testcase_01 | AC | 682 ms
180,736 KB |
testcase_02 | AC | 808 ms
180,736 KB |
testcase_03 | AC | 357 ms
180,736 KB |
testcase_04 | AC | 387 ms
180,608 KB |
testcase_05 | AC | 1,322 ms
180,736 KB |
testcase_06 | AC | 780 ms
180,736 KB |
testcase_07 | AC | 160 ms
180,608 KB |
testcase_08 | AC | 1,377 ms
180,736 KB |
testcase_09 | AC | 239 ms
180,736 KB |
testcase_10 | WA | - |
testcase_11 | AC | 1,534 ms
180,608 KB |
testcase_12 | WA | - |
testcase_13 | AC | 135 ms
180,736 KB |
testcase_14 | AC | 137 ms
180,736 KB |
testcase_15 | WA | - |
testcase_16 | AC | 288 ms
180,736 KB |
testcase_17 | AC | 139 ms
180,864 KB |
testcase_18 | AC | 139 ms
180,736 KB |
testcase_19 | AC | 139 ms
180,736 KB |
testcase_20 | AC | 142 ms
180,736 KB |
testcase_21 | AC | 136 ms
180,736 KB |
testcase_22 | AC | 139 ms
180,736 KB |
testcase_23 | AC | 137 ms
180,736 KB |
testcase_24 | AC | 138 ms
180,736 KB |
testcase_25 | AC | 136 ms
180,736 KB |
testcase_26 | AC | 139 ms
180,736 KB |
testcase_27 | AC | 775 ms
180,736 KB |
testcase_28 | AC | 1,475 ms
180,736 KB |
testcase_29 | AC | 201 ms
180,736 KB |
testcase_30 | AC | 564 ms
180,608 KB |
ソースコード
/* * @Author: kabbo * @Date: 2020-06-24 08:40:07 * @Last Modified by: kabbo * @Last Modified time: 2020-06-24 08:49:58 */ #include <bits/stdc++.h> using namespace std; #define pii pair<long long, long long> #define endl '\n' #define ull unsigned long long #define ll int64_t #define ar array // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html template <class Fun> class y_combinator_result { Fun fun_; public: template <class T> explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {} template <class... Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template <class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } //const int mod = 1e9 + 7; using u64 = uint64_t; using u128 = __uint128_t; #define sc1(x) scanf("%lld", &(x)); mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifndef NEAL_DEBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif /*Well, probably you won't understand anything, because you didn't try to understand anything in your life, you expect all hard work to be done for you by someone else. Let's start*/ const int X = 20000; bitset<X> is_prime; vector<int> pf; vector<int> pr; void init() { pf.resize(X, 0); is_prime.flip(); is_prime[0] = is_prime[1] = false; for (int i = 2; i < X; i++) { if (is_prime[i]) { pr.push_back(i); pf[i] = i; } for (int p : pr) { if (ll(i) * p >= X) break; pf[i * p] = p; is_prime[i * p] = false; if (i % p == 0) break; } } } void solve() { int n; cin >> n; int sz = pr.size(); // dbg(sz); vector memo(sz + 5, vector(X + 1, (int)-1)); auto dp = y_combinator( [&](auto self, int st, int n) -> int { if (n < 0) return -(int)1e5; if (st == sz) { if (n == 0) return 0; else return -(int)1e5; } int &res = memo[st][n]; if (res != -1) return res; int a1 = 1 + self(st + 1, n - pr[st]); int a2 = self(st + 1, n); return res = max(a1, a2); } ); cout << dp(0, n) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); init(); solve(); return 0; }