#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char*s, const H &h, T ...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr (sizeof...(T)) qqbx(++s, args...);
}
#else
#include "biscuits.h"
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
using namespace std;
typedef long long ll;
const int N = 2500025;
bool check(ll y, ll x, vector<ll> a) {
int k = a.size();
ll now = 0;
for(int i = 0; i < k; i++) {
now += a[i] << i;
ll m = y & ((1LL<<i+1)-1);
if(now < x * m) return false;
}
return true;
}
ll count_tastiness(ll x, vector<ll> a) {
int k = a.size();
cerr << x << '\n';
for(int i = 0; i < k; i++) cerr << a[i] << (i+1==k ? '\n' : ' ');
vector<ll> sum(k);
sum[0] = a[0];
for(int i = 1; i < k; i++) sum[i] = sum[i-1] + (a[i] << i);
for(int i = 0; i < k; i++) sum[i] /= x;
vector<map<ll,ll>> mp(k);
// count how many y, \forall i, (y & (11...11)) <= lim
function<ll(int,ll)> calc = [&](int i, ll lim) -> ll {
if(lim < 0) return 0;
if(lim > sum[i]) lim = sum[i];
if(i == 0) return lim + 1;
if(mp[i].count(lim)) return mp[i][lim];
if(lim >= (1LL>>i))
return mp[i][lim] = calc(i-1, lim-(1LL<<i)) + calc(i-1, lim);
return mp[i][lim] = calc(i-1, lim);
};
ll ans = calc(k-1, sum[k-1]);
debug(ans);
return ans;
}
#ifdef local
signed main() {
count_tastiness(3, {5, 2, 1});
count_tastiness(2, {2, 1, 2});
}
#endif // local
Compilation message
biscuits.cpp: In function 'bool check(ll, ll, std::vector<long long int>)':
biscuits.cpp:26:28: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
26 | ll m = y & ((1LL<<i+1)-1);
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
384 KB |
Output is correct |
2 |
Correct |
301 ms |
1236 KB |
Output is correct |
3 |
Correct |
297 ms |
1272 KB |
Output is correct |
4 |
Correct |
305 ms |
1272 KB |
Output is correct |
5 |
Correct |
294 ms |
1404 KB |
Output is correct |
6 |
Correct |
309 ms |
1288 KB |
Output is correct |
7 |
Correct |
304 ms |
1276 KB |
Output is correct |
8 |
Correct |
302 ms |
1272 KB |
Output is correct |
9 |
Correct |
301 ms |
1272 KB |
Output is correct |
10 |
Correct |
289 ms |
1240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |