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")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
ll m;
cin >> n >> m;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int left_sz = n / 2, right_sz = n - left_sz;
int topkek = 1 << right_sz;
vector<ll> weights;
for (int mask = 0; mask < topkek; mask++) {
ll kek = 0;
for (int i = 0; i < right_sz; i++) {
if (mask & (1 << i)) {
kek += a[left_sz + i];
}
}
weights.push_back(kek);
}
topkek = 1 << left_sz;
ll ans = 0;
sort(weights.begin(), weights.end());
for (int mask = 0; mask < topkek; mask++) {
ll kek = 0;
for (int i = 0; i < left_sz; i++) {
if (mask & (1 << i)) {
kek += a[i];
}
}
ans += upper_bound(weights.begin(), weights.end(), m - kek) - weights.begin();
}
cout << ans;
return 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... |
# | 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... |