#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;
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) v2.pb(sum);
}
sort(all(v2));
for(int u : v1)
{
// find num of elements in v2 that are <=m-v1[i]
ans+=bs(m-u);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
1228 KB |
Output is correct |
2 |
Correct |
106 ms |
2876 KB |
Output is correct |
3 |
Correct |
512 ms |
10668 KB |
Output is correct |
4 |
Correct |
113 ms |
2756 KB |
Output is correct |
5 |
Correct |
15 ms |
976 KB |
Output is correct |
6 |
Correct |
9 ms |
588 KB |
Output is correct |
7 |
Correct |
9 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
1484 KB |
Output is correct |
2 |
Correct |
36 ms |
1208 KB |
Output is correct |
3 |
Correct |
191 ms |
5436 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
588 KB |
Output is correct |
6 |
Correct |
15 ms |
920 KB |
Output is correct |
7 |
Correct |
9 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
1860 KB |
Output is correct |
2 |
Correct |
150 ms |
3512 KB |
Output is correct |
3 |
Correct |
149 ms |
3476 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
87 ms |
3600 KB |
Output is correct |
6 |
Correct |
292 ms |
10512 KB |
Output is correct |
7 |
Correct |
52 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
339 ms |
6572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
1228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
542 ms |
10456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |