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"
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
const int N=1e5+5;
bitset<N> bs;
ll p2(ll x, vector<ll> a) {
while (a.size()<=60) a.pb(0);
ll s=1;
int k=0;
while (k<60 && (a[k]==0 || s>=(1ll<<k))) {
s+=(a[k]<<k);
++k;
}
ll old=s;
ll s2=1;
for (int t=k; t<60; ++t) {
if (!a[t]) continue;
if (s2 >= (1ll<<(t-k))) {
s2+=(a[t]<<(t-k));
} else {
s=s2*old;
old=s;
s2=1;
k=t;
--t;
}
}
s=s2*old;
old=s;
s2=1;
return s;
}
ll f(ll x, vector<ll>&a, int i) {
if (i>=a.size()-1) return 1+(a[i]/x);
if (a[i]>=x) {
a[i+1]+=(a[i]-x)>>1;
ll q1=f(x,a,i+1);
a[i+1]-=(a[i]-x)>>1;
a[i+1]+=(a[i])>>1;
ll q2=f(x,a,i+1);
a[i+1]-=(a[i])>>1;
return q1+q2;
} else {
a[i+1]+=(a[i])>>1;
ll q=f(x,a,i+1);
a[i+1]-=(a[i])>>1;
return q;
}
}
int v[2][2*N];
int sz[2];
ll count_tastiness(ll x, vector<ll> a) {
if (x==1) {
return p2(x,a);
}
sz[0]=1;
v[0][0]=0;
int n=a.size();
forn(i,n) {
int b=i&1;
sz[!b]=0;
forn(t,sz[b]) {
if (a[i]+v[b][t]<x) {
v[!b][sz[!b]]=(a[i]+v[b][t])>>1;
sz[!b]++;
} else {
v[!b][sz[!b]]=(a[i]+v[b][t]-x)>>1;
sz[!b]++;
v[!b][sz[!b]]=(a[i]+v[b][t])>>1;
sz[!b]++;
}
}
}
int ans = sz[n&1];
forn(t,sz[n&1]) ans+=v[n&1][t]/x;
return ans;
}
Compilation message (stderr)
biscuits.cpp: In function 'll f(ll, std::vector<long long int>&, int)':
biscuits.cpp:43:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if (i>=a.size()-1) return 1+(a[i]/x);
| ~^~~~~~~~~~~~
# | 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... |