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 pii pair<int,int>
#define ll long long
using namespace std;
vector<ll> v1;
vector<ll> v2;
ll a[45];
ll clc(int mask,int b,int e,ll m)
{
ll cur=0;
for(int i=b,j=1;i<=e;i++,j++)
{
if((mask>>(j-1))&1)
{
if(cur+a[i]>m)return -1;
cur+=a[i];
}
}
return cur;
}
int main()
{
int n;
cin>>n;
int m;
cin>>m;
int m1=n/2;
int m2=n-m1;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=0;i<(1<<m1)-1;i++)
{
ll c=clc(i,1,m1,m);
if(c!=-1)v1.push_back(c);
}
for(int i=0;i<(1<<m2)-1;i++)
{
ll c=clc(i,m1+1,n,m);
if(c!=-1)v2.push_back(c);
}
sort(v2.begin(),v2.end());
ll rs=0;
for(int i=0;i<v1.size();i++)
{
ll cur=v1[i];
ll r=m-cur;
ll d=upper_bound(v2.begin(),v2.end(),r)-v2.begin();
rs+=d;
}
cout<<rs<<endl;
return 0;
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:65:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v1.size();i++)
~^~~~~~~~~~
# | 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... |