#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAX_N = 40 + 2;
int n;
lint m;
lint c[MAX_N];
void solve_edge() {
if (n != 1) return;
lint ans = 1 + (bool) (c[1] <= m);
cout << ans << '\n';
exit(0);
}
int size1, size2;
vector<lint> ord_costs;
void precomp() {
size1 = n / 2;
size2 = n - n / 2;
for (int mask = 0; mask < (1 << size2); mask++) {
lint cost = 0;
for (int b = 0; b < size2; b++) {
if (!(mask & (1 << b))) continue;
cost += c[n / 2 + 1 + b];
}
ord_costs.push_back(cost);
}
sort(ord_costs.begin(), ord_costs.end());
}
int main() {
// freopen("ice.in", "r", stdin);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> c[i];
solve_edge();
precomp();
lint ans = 0;
for (int mask = 0; mask < (1 << size1); mask++) {
lint cost = 0;
for (int b = 0; b < size1; b++) {
if (!(mask & (1 << b))) continue;
cost += c[1 + b];
}
lint tar_cost = m - cost;
lint tar_ind = upper_bound(ord_costs.begin(), ord_costs.end(), tar_cost) - ord_costs.begin();
ans += tar_ind;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 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 |
600 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 |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
360 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
1492 KB |
Output is correct |
2 |
Correct |
85 ms |
2540 KB |
Output is correct |
3 |
Correct |
396 ms |
9928 KB |
Output is correct |
4 |
Correct |
83 ms |
2508 KB |
Output is correct |
5 |
Correct |
14 ms |
980 KB |
Output is correct |
6 |
Correct |
6 ms |
728 KB |
Output is correct |
7 |
Correct |
13 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
1492 KB |
Output is correct |
2 |
Correct |
28 ms |
1492 KB |
Output is correct |
3 |
Correct |
165 ms |
6348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
728 KB |
Output is correct |
6 |
Correct |
15 ms |
980 KB |
Output is correct |
7 |
Correct |
13 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
2512 KB |
Output is correct |
2 |
Correct |
123 ms |
4812 KB |
Output is correct |
3 |
Correct |
129 ms |
6196 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
73 ms |
6496 KB |
Output is correct |
6 |
Correct |
220 ms |
9672 KB |
Output is correct |
7 |
Correct |
88 ms |
4812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
9152 KB |
Output is correct |
2 |
Correct |
26 ms |
1488 KB |
Output is correct |
3 |
Correct |
9 ms |
728 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
728 KB |
Output is correct |
6 |
Correct |
193 ms |
10428 KB |
Output is correct |
7 |
Correct |
13 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
1488 KB |
Output is correct |
2 |
Correct |
83 ms |
2512 KB |
Output is correct |
3 |
Correct |
8 ms |
728 KB |
Output is correct |
4 |
Correct |
8 ms |
980 KB |
Output is correct |
5 |
Correct |
89 ms |
6348 KB |
Output is correct |
6 |
Correct |
22 ms |
1556 KB |
Output is correct |
7 |
Correct |
229 ms |
10424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
9592 KB |
Output is correct |
2 |
Correct |
32 ms |
1488 KB |
Output is correct |
3 |
Correct |
8 ms |
728 KB |
Output is correct |
4 |
Correct |
419 ms |
9408 KB |
Output is correct |
5 |
Correct |
114 ms |
5580 KB |
Output is correct |
6 |
Correct |
13 ms |
980 KB |
Output is correct |
7 |
Correct |
26 ms |
1480 KB |
Output is correct |