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;
using ll = long long;
int mod = 1e9 + 7;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
ll m;
cin>>n>>m;
ll a[n];
for(int i = 0; i < n; i++)cin>>a[i];
// [0, n / 2 - 1], [n / 2, n - 1]
vector<ll>v;
for(int mask = 0; mask < (1 << ((n+1)>>1)); mask++){
ll sum = 0;
for(int i = 0; i < (n+1)/2; i++){
if(mask & (1 << i))
sum += a[i + (n >> 1)];
}
v.push_back(sum);
}
sort(v.begin(), v.end());
ll ans = 0;
for(int mask = 0; mask < (1 << (n >> 1)); mask++){
ll sum = 0;
for(int i = 0; i < (n >> 1); i++){
if(mask & (1 << i))
sum += a[i];
}
ans += upper_bound(v.begin(), v.end(), m - sum) - v.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... |