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 <bits/stdc++.h>
#include "biscuits.h"
using namespace std;
#define vt vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(int (i) = 0; (i) < (x); (i)++)
typedef long long ll;
typedef long double ld;
typedef vt<int> vi;
typedef pair<int,int> pii;
vt<ll> A;
ll X;
int k;
bool works(ll cur){
ll now = 0;
ll lat = 0;
for(int i = 0; i < 60; i++){
if(i<k)
now+=A[i]*(1ll<<i);
lat+=((1ll<<i)&cur)*X;
if(now<lat)return false;
}
return true;
}
ll brute_force(ll x, vt<ll> a){
if(x>100000)return 1;
X = x; A = a;k =a.size();
ll ans = 0;
for(ll i = 100000; i >= 0; i--){
if(works(i))ans++;
}
return ans;
}
map<pair<long,long>,long> mp;
ll mthcount(ll x, int cur, ll val){
if(cur==k-1){
return val/x+1;
}
if(val >= x){
ll ans = 0;
if(mp.find({cur+1,val/2+A[cur+1]})!=mp.end()){
ans+=mp[{cur+1,val/2+A[cur+1]}];
}else{
ans+=mthcount(x,cur+1,val/2+A[cur+1]);
mp[{cur+1,val/2+A[cur+1]}] = ans;
}
val-=x;
if(mp.find({cur+1,val/2+A[cur+1]})!=mp.end()){
ans+=mp[{cur+1,val/2+A[cur+1]}];
}else{
mp[{cur+1,val/2+A[cur+1]}] = mthcount(x,cur+1,val/2+A[cur+1]);
ans+=mp[{cur+1,val/2+A[cur+1]}];
}
return ans;
}else{
if(mp.find({cur+1,val/2+A[cur+1]})!=mp.end()){
return mp[{cur+1,val/2+A[cur+1]}];
}else{
mp[{cur+1,val/2+A[cur+1]}] = mthcount(x,cur+1,val/2+A[cur+1]);
return mp[{cur+1,val/2+A[cur+1]}];
}
}
}
ll count_tastiness(ll x, vt<ll> a){
mp.clear();
A = a;
k = a.size();
return mthcount(x,0,a[0]);
}
# | 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... |