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 <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e6+5;
long long arr[MAXN];
long long dp[MAXN];
long long dp2[MAXN];
vector<long long> v1;
int main(){
long long ans = 0;
long long n,m;
cin>>n>>m;
for(long long i=0;i<n;i++){
cin>>arr[i];
}
for(long long i=0;i<(1LL<<(n/2));i++){
for(long long j=0;j<(n/2);j++){
if(i&(1LL<<j)){
dp[i] += arr[j];
}
}
v1.push_back(dp[i]);
}
sort(v1.begin(),v1.end());
long long tmp = (n/2)+(n%2>0);
for(long long i=0;i<(1LL<<(tmp));i++){
for(long long j=0;j<(tmp);j++){
if(i&(1LL<<j)){
dp2[i] += arr[j+(n/2)];
}
}
//cout<<dp2[i]<<endl;
}
for(long long i=0;i<(1LL<<(tmp));i++){
long long target = m-dp2[i];
if(target>=0){
long long pos = upper_bound(v1.begin(),v1.end(),target)-v1.begin();
//cout<<dp2[i]<<" "<<target<<" "<<pos<<endl;
ans+=(pos);
}
}
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... |