//In the name of Allah
//SMani24
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << endl
#define int long long
using namespace std;
const int N = 42;
int n, m, ans;
int a[N], dpu[1 << (N / 2)], dpd[1 << (N / 2)], prep[1 << (N / 2)];
void set_prep() {
for (int i = 0; i < N / 2; i++)
prep[1 << i] = i;
}
void read_input() {
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
}
void solve() {
set_prep();
int nu = n / 2, nd = (n + 1) / 2;
for (int mask = 1; mask < (1 << nu); mask++)
dpu[mask] = dpu[mask ^ (mask & -mask)] + a[prep[mask & -mask]];
for (int mask = 1; mask < (1 << nd); mask++)
dpd[mask] = dpd[mask ^ (mask & -mask)] + a[prep[mask & -mask] + nu];
sort(dpu, dpu + (1 << nu));
sort(dpd, dpd + (1 << nd));
for (int i = 0; i < (1 << nu); i++) {
if (dpu[i] > m)
break;
ans += upper_bound(dpd, dpd + (1 << nd), m - dpu[i]) - dpd;
}
}
void write_output() {
cout << ans << endl;
}
int32_t main() {
ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
read_input(), solve(), write_output();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2040 KB |
Output is correct |
2 |
Correct |
65 ms |
4472 KB |
Output is correct |
3 |
Correct |
267 ms |
16760 KB |
Output is correct |
4 |
Correct |
65 ms |
4472 KB |
Output is correct |
5 |
Correct |
12 ms |
1400 KB |
Output is correct |
6 |
Correct |
11 ms |
888 KB |
Output is correct |
7 |
Correct |
15 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2424 KB |
Output is correct |
2 |
Correct |
25 ms |
1912 KB |
Output is correct |
3 |
Correct |
97 ms |
8568 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
8 ms |
888 KB |
Output is correct |
6 |
Correct |
19 ms |
1400 KB |
Output is correct |
7 |
Correct |
16 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
3448 KB |
Output is correct |
2 |
Correct |
95 ms |
6524 KB |
Output is correct |
3 |
Correct |
93 ms |
6620 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
42 ms |
6648 KB |
Output is correct |
6 |
Correct |
212 ms |
16760 KB |
Output is correct |
7 |
Correct |
77 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
12668 KB |
Output is correct |
2 |
Correct |
24 ms |
1912 KB |
Output is correct |
3 |
Correct |
11 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
8 ms |
888 KB |
Output is correct |
6 |
Correct |
181 ms |
12664 KB |
Output is correct |
7 |
Correct |
15 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1912 KB |
Output is correct |
2 |
Correct |
65 ms |
4472 KB |
Output is correct |
3 |
Correct |
11 ms |
888 KB |
Output is correct |
4 |
Correct |
11 ms |
892 KB |
Output is correct |
5 |
Correct |
48 ms |
6520 KB |
Output is correct |
6 |
Correct |
24 ms |
1912 KB |
Output is correct |
7 |
Correct |
208 ms |
16876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
16760 KB |
Output is correct |
2 |
Correct |
25 ms |
1916 KB |
Output is correct |
3 |
Correct |
11 ms |
888 KB |
Output is correct |
4 |
Correct |
272 ms |
16888 KB |
Output is correct |
5 |
Correct |
65 ms |
8568 KB |
Output is correct |
6 |
Correct |
16 ms |
1528 KB |
Output is correct |
7 |
Correct |
27 ms |
2516 KB |
Output is correct |