#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<ll, int> res;
const ll MAX = 1'000'000'000'000'000'000;
ll s[100];
int find(ll r){
if(r < 0) return 0;
if(r == 0) return 1;
if(res.count(r))
return res[r];
int i = (int)floor(log2(r));
while((1LL << i ) > r )
--i;
return res[r] = find((1LL << i) - 1) + find(min(r, s[i])- (1LL << i));
}
long long count_tastiness(long long x, std::vector<long long> a) {
res.clear();
while(a.size() < 60)
a.push_back(0);
for(int i = 0; i < 59; ++i){
ll t = max(0LL, (a[i] - x) / 2);
a[i] -= t * 2;
a[i + 1] += t;
}
a[59] = min(a[59], x + 1);
ll t = 0;
s[0] = a[0] / x;
t = a[0] % x;
for(int i = 1; i < 60; ++i){
s[i] = s[i - 1];
for(int j = i; j > 0; --j){
while(a[i] >= x){
s[i] = min(MAX, s[i] + (1LL << j));
a[i] -= x;
}
a[i] <<= 1;
}
while(a[i] >= x){
a[i] -= x;
++s[i];
}
t += a[i];
while(t >= x){
t -= x;
++s[i];
}
}
return find(MAX);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
332 KB |
Output is correct |
2 |
Correct |
36 ms |
1188 KB |
Output is correct |
3 |
Correct |
33 ms |
1204 KB |
Output is correct |
4 |
Correct |
34 ms |
1180 KB |
Output is correct |
5 |
Correct |
37 ms |
1100 KB |
Output is correct |
6 |
Correct |
41 ms |
1128 KB |
Output is correct |
7 |
Correct |
40 ms |
1100 KB |
Output is correct |
8 |
Correct |
39 ms |
1100 KB |
Output is correct |
9 |
Correct |
37 ms |
1100 KB |
Output is correct |
10 |
Correct |
29 ms |
1164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |