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;
#define int long long
const int sz=2e6+5;
const int INF=1e18;
const int MOD=1e9+7;
int arr[sz],mask_arr1[sz],mask_arr2[sz];
void solve()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>arr[i];
int res=0;
int cur=n/2;
for(int mask=0;mask<(1<<cur);mask++)
{
int cur_money=0;
for(int i=0;i<cur;i++)
if(mask&(1<<i))
cur_money+=arr[i];
mask_arr1[mask]=cur_money;
}
for(int mask=0;mask<(1<<(n-cur));mask++)
{
int cur_money=0;
for(int i=0;i<(n-cur);i++)
if(mask&(1<<i))
cur_money+=arr[i+cur];
mask_arr2[mask]=cur_money;
}
sort(mask_arr2,mask_arr2+(1<<(n-cur)));
for(int i=0;i<(1<<cur);i++)
{
if(mask_arr1[i]<=m)
{
int ind=upper_bound(mask_arr2,mask_arr2+(1<<(n-cur)),m-mask_arr1[i])-mask_arr2;
ind--;
if(mask_arr1[i]+mask_arr2[ind]<=m)
res+=ind+1;
}
}
cout<<res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
}
# | 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... |