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>
#pragma GCC optimize("O3")
#define endl '\n'
using namespace std;
const long double eps = 1e-18;
long long count_tastiness(long long x, vector <long long> a) {
long double c = 0;
long long d = 1;
long long ans = 1;
int sz = (int)a.size();
for (int i = 0; ; i++) {
c /= 2.0;
if (i < sz)
c += (long double)a[i];
if (c < x - eps && i >= sz)
break;
if (c < x) {
d <<= 1ll;
continue;
}
//cout << c << "wtf" << endl;
long long low = 0, high = d-1;
while (low < high) {
long long mid = (low + high + 1) >> 1ll;
long double res = c - (long double)x / (long double)d * (long double)mid;
if (res > x + eps || fabs(res - x) < eps)
low = mid;
else
high = mid-1;
}
ans += low + 1;
//cout << d << " " << low << " " << c << endl;
d <<= 1ll;
}
return ans;
}
/*
int main() {
long long x, n;
cin >> x >> n;
vector <long long> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
cout << count_tastiness(x, a) << endl;
}
*/
# | 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... |