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"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define fori for(int i=0;i<n;i++)
#define forj for(int j=0;j<n;j++)
#define pb push_back
#define in insert
#define F first
#define S second
#define endl '\n'
using namespace std;
int main(){
fast;
ll n,x;
cin>>n>>x;
vector<ll>v;
ll a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
ll sum,mid=n/2,mid2=n-mid;
ll ans=0;
for(int i=0;i<(1<<mid);i++){
sum=0;
for(int j=0;j<mid;j++){
if((i & (1<<j))!=0){
sum+=a[j];
}
}
v.pb(sum); //5
}
sort(v.begin(),v.end());
for(int i=0;i<(1<<mid2);i++){
sum=0;
for(int j=0;j<mid2;j++){
if((i & (1<<j))!=0){
sum+=a[j+mid];//10
}
}
auto q=upper_bound(v.begin(),v.end(),x-sum);
ans+=q - v.begin();
}
cout<<ans<<endl;
}
# | 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... |