#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 40;
int N;
ll M;
ll A[maxn], B[maxn];
int main()
{
cin >> N >> M;
ll tot = 0;
int split = N/2;
for (int i = 0; i < split; i++) {
cin >> A[i];
tot += A[i];
}
for (int i = split; i < N; i++) {
cin >> B[i-split];
tot += B[i-split];
}
if (tot <= M) {
cout << (1LL<<N) << '\n';
return 0;
}
vector<ll> as;
for (int i = 0; i < (1<<split); i++) {
ll total = 0;
for (int j = 0; j < split; j++) {
if (i & (1<<j)) total += A[j];
if (total > M) {
break;
}
}
if (total <= M) as.push_back(total);
}
sort(as.begin(),as.end());
ll ans = 0;
for (int i = 0; i < (1<<(N-split)); i++) {
ll total = 0;
for (int j = 0; j < N-split; j++) {
if (i & (1<<j)) total += B[j];
if (total > M) {
break;
}
}
if (total <= M) {
auto it = upper_bound(as.begin(),as.end(),M-total);
ans += distance(as.begin(),it);
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1020 KB |
Output is correct |
2 |
Correct |
105 ms |
2548 KB |
Output is correct |
3 |
Correct |
448 ms |
8648 KB |
Output is correct |
4 |
Correct |
103 ms |
2548 KB |
Output is correct |
5 |
Correct |
16 ms |
1020 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
1528 KB |
Output is correct |
2 |
Correct |
36 ms |
1020 KB |
Output is correct |
3 |
Correct |
206 ms |
4584 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
1528 KB |
Output is correct |
2 |
Correct |
200 ms |
2548 KB |
Output is correct |
3 |
Correct |
155 ms |
2548 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
93 ms |
2548 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
4584 KB |
Output is correct |
2 |
Correct |
31 ms |
1020 KB |
Output is correct |
3 |
Correct |
11 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
10 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
1020 KB |
Output is correct |
2 |
Correct |
100 ms |
2548 KB |
Output is correct |
3 |
Correct |
10 ms |
768 KB |
Output is correct |
4 |
Correct |
10 ms |
768 KB |
Output is correct |
5 |
Correct |
119 ms |
2548 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
11 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
419 ms |
8676 KB |
Output is correct |
2 |
Correct |
41 ms |
1020 KB |
Output is correct |
3 |
Correct |
11 ms |
768 KB |
Output is correct |
4 |
Correct |
770 ms |
8668 KB |
Output is correct |
5 |
Correct |
135 ms |
4592 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |