This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifndef WAIMAI
#include "biscuits.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
ll count_tastiness(ll x, vector<ll> a) {
ll ans = 0;
a.resize(64);
vector<ll> sum(64), dp(64);
sum[0] = a[0];
FOR (i, 1, 63) sum[i] = sum[i - 1] + (a[i] << i);
/*unordered_map<ll, ll> mp[64];
auto rec = [&](auto rec, int i, ll cur)->ll {
if (i < 0) return 1;
if (mp[i].count(cur)) return mp[i][cur];
ll tot = 0;
cur = min(cur, sum[i]);
tot += rec(rec, i - 1, cur);
if ((cur >> i) >= x) tot += rec(rec, i - 1, cur - (x << i));
return mp[i][cur] = tot;
};
return rec(rec, 63, sum[63]);*/
FOR (i, 0, 63) {
ll cur = sum[i];
for (int j = i - 1; j >= 0; j--) {
cur = min(cur, sum[j]);
if ((cur >> j) >= x) {
dp[i] += dp[j];
cur -= x << j;
}
}
dp[i]++;
}
return dp[63];
}
/*
in1
2
3 3
5 2 1
3 2
2 1 2
out1
5
6
*/
#ifdef WAIMAI
int main() {
int q;
assert(scanf("%d", &q) == 1);
vector<int> k(q);
vector<ll> x(q);
vector<vector<ll>> a(q);
vector<ll> results(q);
for (int t = 0; t < q; t++) {
assert(scanf("%d%lld", &k[t], &x[t]) == 2);
a[t] = vector<ll>(k[t]);
for (int i = 0; i < k[t]; i++) {
assert(scanf("%lld", &a[t][i]) == 1);
}
}
fclose(stdin);
for (int t = 0; t < q; t++) {
results[t] = count_tastiness(x[t], a[t]);
}
for (int t = 0; t < q; t++) {
printf("%lld\n", results[t]);
}
fclose(stdout);
return 0;
}
#endif
Compilation message (stderr)
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:27:8: warning: unused variable 'ans' [-Wunused-variable]
27 | ll ans = 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... |