Submission #724913

#TimeUsernameProblemLanguageResultExecution timeMemory
724913MohamedAliSaidanePacking Biscuits (IOI20_biscuits)C++14
42 / 100
1069 ms43432 KiB
#include<bits/stdc++.h> #include "biscuits.h" #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int,int> pii; typedef vector<pii> vpi; #define ff first #define ss second #define pb push_back #define all(x) (x).begin(),(x).end() const ll MOD = 1e9 + 7, INF = 1e18; ll mod(ll x, ll m = MOD) {return (x + m) % m;} int n; ll x, tot = 0ll; vll A; bool check(ll s) { vll B = A; for(int i =0; i < x; i++) { ll cur = s; for(int j = n - 1; j >= 0; j--) { ll q = min(B[j], cur/(1 << j)); cur -= q * (1 << j); B[j] -= q; } if(cur > 0) return false; } return true; } ll sub1() { int ans = 0; for(int i =0; i <= tot/x; i++) { if(i == 0 || check(i)) ans++; } return ans; } unordered_map<ll,ll> dp[61]; ll f(int i, ll sum) { if(i == 60) return 1ll; if(dp[i].find(sum) != dp[i].end()) return dp[i][sum]; if(sum >= x) return dp[i][sum] = f(i + 1, sum/2ll + A[i + 1]) + f(i + 1, (sum - x)/2ll + A[i + 1]); else return dp[i][sum] = f(i + 1, sum/2ll + A[i + 1]); } ll count_tastiness(ll X, vll a) { x = X; A = a; n = (int)(a.size()); while(n < 60) { A.pb(0ll); n++; } for(int i =0 ; i < n; i++) dp[i].clear(); return f(0, a[0]); } /* int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << count_tastiness(1, {2, 1, 2}); } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...