#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
ll a[40];
vector<ll> bitmask(int x, int y) {
int r = y - x;
vector<ll> ret;
FOR(i, 0, (1 << r)) {
ll sm = 0;
FOR(j, 0, r) if (i & (1 << j)) sm += a[x + j];
ret.push_back(sm);
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
ll b;
cin >> n >> b;
FOR(i, 0, n) cin >> a[i];
vector<ll> l = bitmask(0, n / 2), r = bitmask(n / 2, n);
sort(l.begin(), l.end());
sort(r.begin(), r.end());
ll ans = 0;
for (int i : l) {
if (i > b) break;
ans += upper_bound(r.begin(), r.end(), b - i) - r.begin();
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
2032 KB |
Output is correct |
2 |
Correct |
109 ms |
5480 KB |
Output is correct |
3 |
Correct |
460 ms |
20952 KB |
Output is correct |
4 |
Correct |
108 ms |
5480 KB |
Output is correct |
5 |
Correct |
20 ms |
1652 KB |
Output is correct |
6 |
Correct |
13 ms |
1020 KB |
Output is correct |
7 |
Correct |
23 ms |
1652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
2924 KB |
Output is correct |
2 |
Correct |
39 ms |
2036 KB |
Output is correct |
3 |
Correct |
185 ms |
10592 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
10 ms |
1016 KB |
Output is correct |
6 |
Correct |
24 ms |
1648 KB |
Output is correct |
7 |
Correct |
22 ms |
1652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
3572 KB |
Output is correct |
2 |
Correct |
162 ms |
6624 KB |
Output is correct |
3 |
Correct |
159 ms |
6628 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
108 ms |
6752 KB |
Output is correct |
6 |
Correct |
405 ms |
20984 KB |
Output is correct |
7 |
Correct |
144 ms |
6628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
323 ms |
12876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
2032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
451 ms |
20884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |