#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mxN = 40 + 5;
int n;
ll m;
ll a[mxN];
vector<ll> comb_l , comb_r;
void make_combination(){
int mid = n/2;
// comb_l [1 , mid]
int lim = 1<<mid;
for(int mask=0;mask<lim;mask++){
ll sum = 0;
for(int i=0;i<mid;i++){
if((1<<i) & mask) sum += a[i];
if(sum > m) break;
}
if(sum <= m) comb_l.push_back(sum);
}
sort(comb_l.begin() , comb_l.end());
// comb_r
lim = 1<<(n-mid);
for(int mask=0;mask<lim;mask++){
ll sum = 0;
for(int i=0;i<(n-mid);i++){
if((1<<i) & mask) sum += a[i+mid];
if(sum>m) break;
}
if(sum <= m) comb_r.push_back(sum);
}
sort(comb_r.begin() , comb_r.end());
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>> n >> m;
for(int i=0;i<n;i++) cin>> a[i];
make_combination();
// for(auto val : comb_l) cout<< val << " ";
// cout<< "\n";
// for(auto val : comb_r) cout<< val << " ";
// cout<< "\n";
ll ans = 0;
for(ll val : comb_r){
int cnt = upper_bound(comb_l.begin() , comb_l.end() , m - val) - comb_l.begin();
// cout<< cnt << " ";
ans += cnt;
}
// cout<< "\n";
cout<< ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2144 KB |
Output is correct |
2 |
Correct |
78 ms |
5324 KB |
Output is correct |
3 |
Correct |
336 ms |
21064 KB |
Output is correct |
4 |
Correct |
77 ms |
5456 KB |
Output is correct |
5 |
Correct |
13 ms |
1496 KB |
Output is correct |
6 |
Correct |
8 ms |
992 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
2764 KB |
Output is correct |
2 |
Correct |
29 ms |
1960 KB |
Output is correct |
3 |
Correct |
139 ms |
11456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1032 KB |
Output is correct |
6 |
Correct |
16 ms |
1756 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
3556 KB |
Output is correct |
2 |
Correct |
120 ms |
8660 KB |
Output is correct |
3 |
Correct |
118 ms |
8264 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
77 ms |
6816 KB |
Output is correct |
6 |
Correct |
296 ms |
21688 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
244 ms |
14656 KB |
Output is correct |
2 |
Correct |
26 ms |
2140 KB |
Output is correct |
3 |
Correct |
10 ms |
1112 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
229 ms |
13776 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1888 KB |
Output is correct |
2 |
Correct |
82 ms |
5572 KB |
Output is correct |
3 |
Correct |
8 ms |
992 KB |
Output is correct |
4 |
Correct |
8 ms |
992 KB |
Output is correct |
5 |
Correct |
81 ms |
8468 KB |
Output is correct |
6 |
Correct |
27 ms |
2144 KB |
Output is correct |
7 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
321 ms |
21304 KB |
Output is correct |
2 |
Correct |
27 ms |
1888 KB |
Output is correct |
3 |
Correct |
9 ms |
1112 KB |
Output is correct |
4 |
Correct |
370 ms |
20920 KB |
Output is correct |
5 |
Correct |
108 ms |
11708 KB |
Output is correct |
6 |
Correct |
17 ms |
2008 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |