#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; long long x; cin >> n >> x;
long long a1[n/2], a2[(n+1)/2];
for (auto& y : a1) cin >> y;
for (auto& y : a2) cin >> y;
vector<int> half;
for (int mask = 0; mask < 1 << (n/2); mask++) {
long long sum = 0;
for (int i = 0; i < n/2; i++) {
if (mask & (1 << i)) {
sum += a1[i];
}
}
if (sum <= x) half.push_back(sum);
}
sort(half.begin(), half.end());
long long cnt = 0;
for (int mask = 0; mask < (1 << ((n+1)/2)); mask++) {
long long sum = 0;
for (int i = 0; i < (n+1)/2; i++) {
if (mask & (1 << i)) {
sum += a2[i];
}
}
if (sum <= x) cnt += upper_bound(half.begin(), half.end(), x - sum) - half.begin();
}
cout << cnt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
736 KB |
Output is correct |
2 |
Correct |
77 ms |
1500 KB |
Output is correct |
3 |
Correct |
302 ms |
6604 KB |
Output is correct |
4 |
Correct |
75 ms |
1496 KB |
Output is correct |
5 |
Correct |
11 ms |
732 KB |
Output is correct |
6 |
Correct |
6 ms |
604 KB |
Output is correct |
7 |
Correct |
7 ms |
448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
992 KB |
Output is correct |
2 |
Correct |
25 ms |
736 KB |
Output is correct |
3 |
Correct |
148 ms |
2520 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
604 KB |
Output is correct |
6 |
Correct |
13 ms |
860 KB |
Output is correct |
7 |
Correct |
7 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
992 KB |
Output is correct |
2 |
Correct |
120 ms |
1500 KB |
Output is correct |
3 |
Correct |
109 ms |
1500 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
63 ms |
1624 KB |
Output is correct |
6 |
Correct |
198 ms |
6340 KB |
Output is correct |
7 |
Correct |
42 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
143 ms |
2496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
221 ms |
5064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |