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>
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
using namespace std;
const ll MOD=1e9+7;
// mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
ll n, m, a[45], ans;
vector<int>v1, v2;
ll bs(int x)
{
ll l=0, r=v2.size()-1, mid;
while(l<=r)
{
mid=(l+r)>>1;
if(v2[mid]<=x) l=mid+1;
else r=mid-1;
}
return l;
}
int main()
{
SPEED;
v1.pb(0);
v2.pb(0);
cin>>n>>m;
for(int i=0; i<n; i++)
cin>>a[i];
// [0, n/2);
for(ll i=0; i<(1<<(n>>1)); i++)
{
ll sum=0;
for(ll j=0; j<(n>>1); j++)
{
if(i&(1<<j)) sum+=a[j];
}
if(sum<=m) v1.pb(sum);
}
// [n/2, n);
for(ll i=0; i<(1<<(n-(n>>1))); i++)
{
ll sum=0;
for(ll j=0; j<(n-(n>>1)); j++)
{
if(i&(1<<j)) sum+=a[j+(n>>1)];
}
if(sum<=m) v1.pb(sum);
}
sort(all(v2));
for(int u : v1)
{
ans+=bs(m-u);
}
cout<<ans<<endl;
return 0;
}
# | 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... |