#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';
}
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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1492 KB |
Output is correct |
2 |
Correct |
85 ms |
2512 KB |
Output is correct |
3 |
Correct |
407 ms |
8716 KB |
Output is correct |
4 |
Correct |
84 ms |
2512 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
1492 KB |
Output is correct |
2 |
Correct |
27 ms |
1492 KB |
Output is correct |
3 |
Correct |
167 ms |
4812 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
728 KB |
Output is correct |
6 |
Correct |
15 ms |
984 KB |
Output is correct |
7 |
Correct |
12 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
2540 KB |
Output is correct |
2 |
Correct |
126 ms |
6604 KB |
Output is correct |
3 |
Correct |
131 ms |
6592 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
77 ms |
5472 KB |
Output is correct |
6 |
Correct |
219 ms |
9912 KB |
Output is correct |
7 |
Correct |
92 ms |
6336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
265 ms |
8884 KB |
Output is correct |
2 |
Correct |
25 ms |
1488 KB |
Output is correct |
3 |
Correct |
9 ms |
980 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
728 KB |
Output is correct |
6 |
Correct |
185 ms |
9064 KB |
Output is correct |
7 |
Correct |
12 ms |
984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1488 KB |
Output is correct |
2 |
Correct |
82 ms |
2456 KB |
Output is correct |
3 |
Correct |
8 ms |
728 KB |
Output is correct |
4 |
Correct |
8 ms |
724 KB |
Output is correct |
5 |
Correct |
90 ms |
5060 KB |
Output is correct |
6 |
Correct |
22 ms |
1744 KB |
Output is correct |
7 |
Correct |
226 ms |
9660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
322 ms |
10168 KB |
Output is correct |
2 |
Correct |
30 ms |
1492 KB |
Output is correct |
3 |
Correct |
8 ms |
728 KB |
Output is correct |
4 |
Correct |
399 ms |
9028 KB |
Output is correct |
5 |
Correct |
118 ms |
5324 KB |
Output is correct |
6 |
Correct |
13 ms |
984 KB |
Output is correct |
7 |
Correct |
28 ms |
1492 KB |
Output is correct |