結果
問題 | No.458 異なる素数の和 |
ユーザー | Shivam062004 |
提出日時 | 2024-07-09 04:39:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 3,449 bytes |
コンパイル時間 | 4,157 ms |
コンパイル使用メモリ | 195,104 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-09 04:39:46 |
合計ジャッジ時間 | 6,120 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 12 ms
5,376 KB |
testcase_02 | AC | 16 ms
5,376 KB |
testcase_03 | AC | 4 ms
5,376 KB |
testcase_04 | AC | 5 ms
5,376 KB |
testcase_05 | AC | 33 ms
5,376 KB |
testcase_06 | AC | 15 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 32 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 40 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 1 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 | 1 ms
5,376 KB |
testcase_27 | AC | 14 ms
5,376 KB |
testcase_28 | AC | 38 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 9 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> dp(n+1, -1e18); dp[0] = 0; v prime; for(int i = 0; i <= n; i++) { if(p[i] == 1)prime.pb(i); } for(auto num: prime) { for(int i = n; i >= 0; i--) { if(num + i <= n && dp[i] != -1) { dp[i+num] = max(dp[i]+1, dp[i+num]); } } } cout<<((dp[n] == -1e18)?-1:dp[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; }