#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
int32_t main() {
int n;
ll m, ans = 1;
cin >> n >> m;
vector<ll> v(n);
for(ll &x : v) cin >> x;
auto meet = [&](int l, int r) {
vector<ll> total;
int len = r - l + 1;
for(int s=1; s<(1<<len); s++) {
ll sum = 0;
for(int i=0; i<len; i++)
if(s & (1 << i)) sum += v[l+i];
total.push_back(sum);
if(sum <= m) ans++;
}
sort(all(total));
return total;
};
vector<ll> L = meet(0, n/2-1);
vector<ll> R = meet(n/2, n-1);
for(ll &x : L) {
int l=0, r=R.size()-1, p=-1;
while(l <= r) {
int mid = (l + r) / 2;
if(x + R[mid] <= m) p = mid, l = mid + 1;
else r = mid - 1;
}
ans += p + 1;
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1876 KB |
Output is correct |
2 |
Correct |
80 ms |
5564 KB |
Output is correct |
3 |
Correct |
336 ms |
22700 KB |
Output is correct |
4 |
Correct |
78 ms |
5460 KB |
Output is correct |
5 |
Correct |
13 ms |
1492 KB |
Output is correct |
6 |
Correct |
8 ms |
984 KB |
Output is correct |
7 |
Correct |
17 ms |
1488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2764 KB |
Output is correct |
2 |
Correct |
27 ms |
1988 KB |
Output is correct |
3 |
Correct |
133 ms |
12464 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
980 KB |
Output is correct |
6 |
Correct |
19 ms |
1492 KB |
Output is correct |
7 |
Correct |
16 ms |
1488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
3656 KB |
Output is correct |
2 |
Correct |
114 ms |
6976 KB |
Output is correct |
3 |
Correct |
119 ms |
6832 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
75 ms |
6676 KB |
Output is correct |
6 |
Correct |
277 ms |
22444 KB |
Output is correct |
7 |
Correct |
108 ms |
8204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
14908 KB |
Output is correct |
2 |
Correct |
25 ms |
1876 KB |
Output is correct |
3 |
Correct |
9 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
980 KB |
Output is correct |
6 |
Correct |
225 ms |
14108 KB |
Output is correct |
7 |
Correct |
16 ms |
1488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1876 KB |
Output is correct |
2 |
Correct |
75 ms |
5308 KB |
Output is correct |
3 |
Correct |
9 ms |
984 KB |
Output is correct |
4 |
Correct |
9 ms |
980 KB |
Output is correct |
5 |
Correct |
78 ms |
8256 KB |
Output is correct |
6 |
Correct |
25 ms |
1880 KB |
Output is correct |
7 |
Correct |
302 ms |
22584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
316 ms |
21164 KB |
Output is correct |
2 |
Correct |
30 ms |
2132 KB |
Output is correct |
3 |
Correct |
9 ms |
980 KB |
Output is correct |
4 |
Correct |
328 ms |
21932 KB |
Output is correct |
5 |
Correct |
109 ms |
12212 KB |
Output is correct |
6 |
Correct |
16 ms |
1492 KB |
Output is correct |
7 |
Correct |
34 ms |
3024 KB |
Output is correct |