This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//besmellah
#include <bits/stdc++.h>
using namespace std;
#define int long long
int sum[1 << 20], a[40];
vector <int> V;
int32_t main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
V.push_back(0);
for (int mask = 1; mask < (1 << (n / 2)); mask++) {
sum[mask] = sum[mask - (mask & -mask)] + a[__builtin_ctz(mask)];
V.push_back(sum[mask]);
}
sort(V.begin(), V.end());
int ans = 0;
ans += upper_bound(V.begin(), V.end(), m) - V.begin();
for (int mask = 1; mask < (1 << ((n + 1) / 2)); mask++) {
sum[mask] = sum[mask - (mask & -mask)] + a[n / 2 + __builtin_ctz(mask)];
ans += upper_bound(V.begin(), V.end(), m - sum[mask]) - V.begin();
}
cout << ans;
}
# | 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... |