結果
問題 | No.458 異なる素数の和 |
ユーザー | Shivam062004 |
提出日時 | 2024-07-09 21:27:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 3,644 bytes |
コンパイル時間 | 3,748 ms |
コンパイル使用メモリ | 197,268 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-09 21:27:09 |
合計ジャッジ時間 | 6,062 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 25 ms
5,248 KB |
testcase_02 | AC | 31 ms
5,376 KB |
testcase_03 | AC | 7 ms
5,376 KB |
testcase_04 | AC | 8 ms
5,376 KB |
testcase_05 | AC | 72 ms
5,376 KB |
testcase_06 | AC | 30 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 88 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 83 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 5 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 29 ms
5,376 KB |
testcase_28 | AC | 81 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 19 ms
5,376 KB |
ソースコード
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key //find by order-> element at ith idx(starting from 0)//gives iterator to that index//if not present *it gives 0 //order of key-> number of element less than a number #define int long long int // #define ll long long int #define loop(s, e) for(int i = s; i < e; i++) #define rloop(e, s) for(int i = e; i>= s; i--) #define v vector<int> // #define vll vector<long long int> #define printyes cout<<"YES\n" #define printno cout<<"NO\n" //COMMENT THIS FOR INTERACTIVE PROBLEMS............... #define endl '\n' #define mod 1000000007 #define pinf 1e18 #define ninf -1e18 #define printvec(arr) cout<<#arr<<"=> [ ";for(int i = 0; i < arr.size(); i++){cout<<arr[i]<<" ";}cout<<"]"<<endl; #define dbg(x) cout<<"value of "<<#x<<" is => "<<x<<endl; #define all(x) x.begin(), x.end() #define vpii vector<pair<int, int>> #define pii pair<int,int> #define pll pair<ll, ll> #define ff first #define ss second #define pb push_back #define vpll vector<pll> #define here(i) cout<<"here "<<i<<" "<<endl; #define rt return; #define mx max_element #define mn min_element #define asum accumulate int delrow[4] = {-1,0,1,0}; int delcol[4] = {0,1,0,-1}; void printv(v& ans) { for(auto it: ans)cout<<it<<" "; cout<<endl; } int setBit(int n, int bitNo) { n = (n|(1LL<<bitNo)); return n; } int currBit(int n, int bitNo) { return ((n&(1ll<<bitNo)) == 0)?0:1; } int unSetBit(int n, int bitNo) { n = (n&(~(1ll<<bitNo))); return n; } //*************************************************CHECK THE CONSTRAINTS**********************************************************// int f(int a, int b) { if(b == 0)return 1; int res = f(a, b/2); if(b%2 != 0) { return (((res)%mod * (res)%mod)%mod * a)%mod; } else { return ((res)%mod * (res)%mod)%mod; } } vector<bool> sieve(int n) { vector<bool> prime(n+1, 1); prime[0] = 0; prime[1] = 0; for(int i = 2; i*i <= n; i++) { if(prime[i] == 1) { for(int j = i*i; j <= n; j+=i) { prime[j] = 0; } } } return prime; } void pikachu(int tt, int tc) { int n; cin>>n; vector<bool> p = sieve(n); vector<int> primes; for(int i = 0; i <= n; i++) { if(p[i])primes.pb(i); } vector<vector<int>> dp(2, vector<int>(n+1, -1)); dp[0][0] = 0; dp[0][2] = 1; for(int i = 1; i < primes.size(); i++) { for(int num = 0; num <= n; num++) { if(num - primes[i] >= 0 && dp[0][num - primes[i]] != -1) dp[1][num] = max(dp[1][num], dp[0][num-primes[i]] + 1); dp[1][num] = max(dp[1][num], dp[0][num]); } dp[0] = dp[1]; for(auto &e: dp[1])e = -1; dp[1][0] = 0; } cout<<(dp[0][n])<<endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int gsBall = 1; // cin>>gsBall; int tt = gsBall; int tc = 1; while(gsBall--) { pikachu(tt, tc); tc++; } return 0; }