#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)((x).size())
#define pb push_back
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){ cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){ cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 3e5+5;
ll cnt[62][62]; // number of constraints from these ones
ll lm[62]; // what's my constraint?
long long count_tastiness(long long x, std::vector<long long> a) {
while(SZ(a) < 61) a.pb(0);
int K = 61;
ll sm = 0;
memset(cnt, 0, sizeof cnt);
memset(lm, 0, sizeof lm);
for (int i = 0; i<K; ++i) {
sm += (1ll<<i) * a[i];
ll ho = sm / x;
lm[i] = ho;
}
cnt[K-1][K-1] = 1;
ll re = 0;
for (int i = 0; i<=200000; ++i) { bool ok = 1;
for (int j = 0; j<K; ++j) {
if ((i & ((1<<(j+1))-1)) > lm[j]) {
ok = 0; break;
}
}
re += ok;
}
return re;
for (int i = K-1; i>=0; --i) {
ll msk = (1ll<<(i+1)) - 1;
for (int frm = K-1; frm >= i; --frm) {
if (cnt[i][frm]) {
ll dis = lm[frm] & msk;
if (dis > lm[i]) {
cnt[i][i] += cnt[i][frm];
}else{
if (dis == 0) re += cnt[i][frm];
else{
if (dis >= (1ll<<i)) {
// can choose to not take
(i?cnt[i-1][i-1]:re) += cnt[i][frm];
}
{
// need to be restrained
(i?cnt[i-1][frm]:re) += cnt[i][frm];
}
}
}
}
}
}
return re;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
204 KB |
Output is correct |
2 |
Correct |
8 ms |
328 KB |
Output is correct |
3 |
Correct |
19 ms |
324 KB |
Output is correct |
4 |
Correct |
34 ms |
324 KB |
Output is correct |
5 |
Correct |
24 ms |
324 KB |
Output is correct |
6 |
Correct |
48 ms |
300 KB |
Output is correct |
7 |
Correct |
23 ms |
324 KB |
Output is correct |
8 |
Correct |
49 ms |
204 KB |
Output is correct |
9 |
Correct |
27 ms |
316 KB |
Output is correct |
10 |
Correct |
8 ms |
248 KB |
Output is correct |
11 |
Correct |
10 ms |
204 KB |
Output is correct |
12 |
Correct |
32 ms |
324 KB |
Output is correct |
13 |
Correct |
28 ms |
336 KB |
Output is correct |
14 |
Correct |
19 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
332 KB |
Output is correct |
2 |
Incorrect |
58 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
204 KB |
Output is correct |
2 |
Correct |
8 ms |
328 KB |
Output is correct |
3 |
Correct |
19 ms |
324 KB |
Output is correct |
4 |
Correct |
34 ms |
324 KB |
Output is correct |
5 |
Correct |
24 ms |
324 KB |
Output is correct |
6 |
Correct |
48 ms |
300 KB |
Output is correct |
7 |
Correct |
23 ms |
324 KB |
Output is correct |
8 |
Correct |
49 ms |
204 KB |
Output is correct |
9 |
Correct |
27 ms |
316 KB |
Output is correct |
10 |
Correct |
8 ms |
248 KB |
Output is correct |
11 |
Correct |
10 ms |
204 KB |
Output is correct |
12 |
Correct |
32 ms |
324 KB |
Output is correct |
13 |
Correct |
28 ms |
336 KB |
Output is correct |
14 |
Correct |
19 ms |
332 KB |
Output is correct |
15 |
Correct |
22 ms |
332 KB |
Output is correct |
16 |
Incorrect |
58 ms |
204 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |