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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> void check_min(T &a, const T & b){ a = (a < b) ? a : b; }
template<typename T> void check_max(T &a, const T & b){ a = (a > b) ? a : b; }
const int N = 40 + 3;
int n;
ll m, a[N];
vector<ll> v;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < n; ++i)
cin >> a[i];
int half = n / 2;
for(int mask = 0; mask < (1 << half); ++mask){
ll sum = 0;
for(int i = 0; i < half; ++i)
if(mask & (1 << i))
sum += a[i];
v.push_back(sum);
}
sort(v.begin(), v.end());
ll ans = 0;
for(int mask = 0; mask < (1 << (n - half)); ++mask){
ll sum = 0;
for(int i = half; i < n; ++i)
if(mask & (1 << (i - half)))
sum += a[i];
ans += upper_bound(v.begin(), v.end(), m - sum) - v.begin();
}
cout << ans << "\n";
}
# | 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... |