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);
/*if(sum <= x){
int q = upper_bound(v.begin(),v.end(),sum)-lower_bound(v.begin(),v.end(),sum);
ans += q;
}*/
}
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];
}
}
int q;
/* if(sum <= x){
q = upper_bound(v.begin(),v.end(),sum)-lower_bound(v.begin(),v.end(),sum);
ans += q;
}*/
q=upper_bound(v.begin(),v.end(),x-sum)-lower_bound(v.begin(),v.end(),x-sum);
ans+=1;
}
cout<<ans<<endl;
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:45:13: warning: variable 'q' set but not used [-Wunused-but-set-variable]
45 | int q;
| ^
# | 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... |