This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
unordered_map <int,int> dp;
int p2[121];
int A[121],X,K;
int ss[121];
int lg2(int x){
return 63 - __builtin_clzll(x);
}
int dpf(int x){
if (dp.find(x) != dp.end()) return dp[x];
if (x <= 0) return 0;
if (x == 1) return 1;
int i = lg2(x-1);
return dp[x] = dpf(min(ss[i] / X, x-1) - p2[i] + 1) + dpf(p2[i]);
}
long long count_tastiness(long long x, std::vector<long long> a) {
K = a.size(); X = x;
FOR(i,0,K-1) A[i] = a[i];
ss[0] = A[0];
p2[0] = 1;
FOR(i,1,59) p2[i] = p2[i-1] * 2;
FOR(i,1,K-1){
ss[i] = ss[i-1] + p2[i]*A[i];
}
FOR(i,K,60) ss[i] = ss[K-1];
dp.clear();
return dpf(ss[K-1]+1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |