#include <bits/stdc++.h>
#define int long long
#define lowval(x) (x & (-x))
#define lowind __builtin_ctzll
using namespace std;
const int MAXN = 40 + 3;
int n, m, c[MAXN], dp[(1 << (MAXN >> 1))], pd[(1 << (MAXN >> 1))], ans;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> c[i];
for (int i = 1; i < (1 << (n >> 1)); i++) dp[i] = c[lowind(i)] + dp[i - lowval(i)];
for (int i = 1; i < (1 << (n - (n >> 1))); i++) pd[i] = c[lowind(i) + (n >> 1)] + pd[i - lowval(i)];
sort(dp, dp + (1 << (n >> 1)));
sort(pd, pd + (1 << (n - (n >> 1))));
for (int i = 0, j = (1 << (n - (n >> 1))) - 1; i < (1 << (n >> 1)); i++) {
while (~j && pd[j] + dp[i] > m) j--;
ans += j + 1;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 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 |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1864 KB |
Output is correct |
2 |
Correct |
49 ms |
4428 KB |
Output is correct |
3 |
Correct |
210 ms |
16720 KB |
Output is correct |
4 |
Correct |
49 ms |
4428 KB |
Output is correct |
5 |
Correct |
7 ms |
1356 KB |
Output is correct |
6 |
Correct |
6 ms |
844 KB |
Output is correct |
7 |
Correct |
11 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2252 KB |
Output is correct |
2 |
Correct |
18 ms |
1868 KB |
Output is correct |
3 |
Correct |
73 ms |
8524 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
836 KB |
Output is correct |
6 |
Correct |
11 ms |
1356 KB |
Output is correct |
7 |
Correct |
11 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3404 KB |
Output is correct |
2 |
Correct |
73 ms |
6476 KB |
Output is correct |
3 |
Correct |
74 ms |
6468 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
32 ms |
6436 KB |
Output is correct |
6 |
Correct |
159 ms |
16716 KB |
Output is correct |
7 |
Correct |
72 ms |
6476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
12612 KB |
Output is correct |
2 |
Correct |
17 ms |
1868 KB |
Output is correct |
3 |
Correct |
6 ms |
844 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
4 ms |
844 KB |
Output is correct |
6 |
Correct |
148 ms |
12632 KB |
Output is correct |
7 |
Correct |
11 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1864 KB |
Output is correct |
2 |
Correct |
48 ms |
4428 KB |
Output is correct |
3 |
Correct |
6 ms |
808 KB |
Output is correct |
4 |
Correct |
6 ms |
840 KB |
Output is correct |
5 |
Correct |
38 ms |
6476 KB |
Output is correct |
6 |
Correct |
16 ms |
1868 KB |
Output is correct |
7 |
Correct |
196 ms |
16720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
16664 KB |
Output is correct |
2 |
Correct |
19 ms |
1868 KB |
Output is correct |
3 |
Correct |
6 ms |
848 KB |
Output is correct |
4 |
Correct |
212 ms |
16704 KB |
Output is correct |
5 |
Correct |
48 ms |
8524 KB |
Output is correct |
6 |
Correct |
11 ms |
1356 KB |
Output is correct |
7 |
Correct |
22 ms |
2380 KB |
Output is correct |