This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
#ifndef ONLINE_JUDGE
#include "AkbarKING.h" // aska geldi akbarking.h
#else
#define debug(...)
#define debugArr(...)
#define debugG(...)
#endif
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#define int long long
#define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#define ep emplace_back
#define pb push_back
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int sz = 3e5+9;
const int LOG = 63;
const int MOD = 1e9+7;
const int INF = 1e18;
int a[LOG];
int n,m;
vector<int>rHalf;
void solve()
{
cin>>n>>m;
for (int i = 1; i <= n ; ++i)
{
cin>>a[i];
}
if (n == 1)
{
cout<<1+(a[1] <= m)<<'\n';
return;
}
for (int mask = 0; mask < (1LL<<(n - n/2)); ++mask)
{
int sm = 0;
for (int i = 0; i < (n - n/2); ++i)
{
if (mask & (1LL<<i))
{
sm += a[n/2+1+i];
}
}
rHalf.ep(sm);
}
sort(all(rHalf));
int res = 0;
for (int mask = 0; mask < (1LL<<(n/2)); ++mask)
{
int sm = 0;
for (int i = 0; i < n/2; ++i)
{
if (mask & (1LL<<i))
{
sm += a[i+1];
}
}
res += upper_bound(all(rHalf),m-sm)-rHalf.begin();;
}
cout<<res<<'\n';
}
signed main()
{
$AzH_TxdmN$
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... |