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 <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <bitset>
#include <chrono>
using namespace std;
typedef long long ll;
#include "biscuits.h"
long long count_tastiness(long long x, std::vector<long long> a) {
/*int k = a.size();
vector <pair <ll, ll>> dp;
dp.push_back({0, 1});
for (int i = 0; i < k; ++i) {
vector <pair <ll, ll>> ndp;
for (auto p : dp) {
p.first += a[i];
if (p.first >= x) {
ndp.push_back(make_pair((p.first - x) / 2, p.second));
}
ndp.push_back(make_pair(p.first / 2, p.second));
}
sort(ndp.begin(), ndp.end());
dp.clear();
for (auto p : ndp) {
if (dp.empty() || dp.back().first != p.first) dp.push_back(p);
else dp.back().second += p.second;
}
}
ll ans = 0;
for (auto p : dp) ans += p.second;
return ans;*/
int k = a.size();
ll ans = 0;
for (int go = 0; go < min((ll)100000, 1LL << k); ++go) {
ll have = 0;
int bad = 0;
for (int i = 0; i < k; ++i) {
have += a[i];
if (go & (1LL << i)) {
have -= x;
if (have < 0) {
bad = 1;
break;
}
}
have /= 2;
}
if (!bad) ++ans;
}
return ans;
}
#ifdef LOCAL
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int q;
cin >> q;
vector<int> k(q);
vector<long long> x(q);
vector<vector<long long>> a(q);
vector<long long> results(q);
for (int t = 0; t < q; t++) {
cin >> k[t] >> x[t];
a[t] = vector<long long>(k[t]);
for (int i = 0; i < k[t]; i++) {
cin >> a[t][i];
}
}
for (int t = 0; t < q; t++) {
results[t] = count_tastiness(x[t], a[t]);
}
for (int t = 0; t < q; t++) {
cout << results[t] << '\n';;
}
}
#endif
# | 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... |