#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, m, arr[50], res1[1100010], res2[1100010], ans;
vector<ll> dp1, dp2;
void find(int idx, ll mon, int cur, int lim, ll res[]) {
if(cur > lim) {
res[idx] = mon;
return;
}
if(mon + arr[cur] <= m) find(idx+pow(2, lim-cur), mon+arr[cur], cur+1, lim, res);
find(idx, mon, cur+1, lim, res);
if(cur == lim) res[idx] = mon;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1; i<=n; i++) {
cin >> arr[i];
}
for(int i=0; i<1100010; i++) {
res1[i] = -1;
res2[i] = -1;
}
find(0, 0, 1, n/2, res1);
find(0, 0, (n/2)+1, n, res2);
for(int i=0; i<1100010; i++) {
if(res1[i] != -1) dp1.push_back(res1[i]);
if(res2[i] != -1) dp2.push_back(res2[i]);
}
sort(dp2.begin(), dp2.end());
for(int i=0; i<dp1.size(); i++) {
ans += lower_bound(dp2.begin(), dp2.end(), m-dp1[i]+1) - dp2.begin();
}
cout << ans;
}
Compilation message
bobek.cpp: In function 'int main()':
bobek.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=0; i<dp1.size(); i++) {
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
17500 KB |
Output is correct |
2 |
Correct |
4 ms |
17544 KB |
Output is correct |
3 |
Correct |
4 ms |
17500 KB |
Output is correct |
4 |
Correct |
4 ms |
17500 KB |
Output is correct |
5 |
Correct |
5 ms |
17500 KB |
Output is correct |
6 |
Correct |
4 ms |
17500 KB |
Output is correct |
7 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
17500 KB |
Output is correct |
2 |
Correct |
4 ms |
17500 KB |
Output is correct |
3 |
Correct |
4 ms |
17500 KB |
Output is correct |
4 |
Correct |
3 ms |
17500 KB |
Output is correct |
5 |
Correct |
4 ms |
17496 KB |
Output is correct |
6 |
Correct |
5 ms |
17752 KB |
Output is correct |
7 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
17500 KB |
Output is correct |
2 |
Correct |
4 ms |
17500 KB |
Output is correct |
3 |
Correct |
4 ms |
17500 KB |
Output is correct |
4 |
Correct |
4 ms |
17500 KB |
Output is correct |
5 |
Correct |
4 ms |
17500 KB |
Output is correct |
6 |
Correct |
4 ms |
17500 KB |
Output is correct |
7 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
19408 KB |
Output is correct |
2 |
Correct |
68 ms |
21856 KB |
Output is correct |
3 |
Correct |
299 ms |
34216 KB |
Output is correct |
4 |
Correct |
67 ms |
21952 KB |
Output is correct |
5 |
Correct |
12 ms |
18896 KB |
Output is correct |
6 |
Correct |
7 ms |
18392 KB |
Output is correct |
7 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
19908 KB |
Output is correct |
2 |
Correct |
23 ms |
19408 KB |
Output is correct |
3 |
Correct |
134 ms |
25952 KB |
Output is correct |
4 |
Correct |
4 ms |
17500 KB |
Output is correct |
5 |
Correct |
7 ms |
18388 KB |
Output is correct |
6 |
Correct |
13 ms |
18896 KB |
Output is correct |
7 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
20936 KB |
Output is correct |
2 |
Correct |
92 ms |
25704 KB |
Output is correct |
3 |
Correct |
97 ms |
24840 KB |
Output is correct |
4 |
Correct |
4 ms |
17496 KB |
Output is correct |
5 |
Correct |
49 ms |
25960 KB |
Output is correct |
6 |
Correct |
133 ms |
34452 KB |
Output is correct |
7 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
199 ms |
31916 KB |
Output is correct |
2 |
Correct |
24 ms |
19408 KB |
Output is correct |
3 |
Correct |
10 ms |
18308 KB |
Output is correct |
4 |
Correct |
4 ms |
17496 KB |
Output is correct |
5 |
Correct |
7 ms |
18392 KB |
Output is correct |
6 |
Correct |
123 ms |
32184 KB |
Output is correct |
7 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
19408 KB |
Output is correct |
2 |
Correct |
68 ms |
21876 KB |
Output is correct |
3 |
Correct |
9 ms |
18388 KB |
Output is correct |
4 |
Correct |
10 ms |
18392 KB |
Output is correct |
5 |
Correct |
46 ms |
24512 KB |
Output is correct |
6 |
Correct |
18 ms |
19404 KB |
Output is correct |
7 |
Correct |
4 ms |
17496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
34120 KB |
Output is correct |
2 |
Correct |
24 ms |
19404 KB |
Output is correct |
3 |
Correct |
9 ms |
18308 KB |
Output is correct |
4 |
Correct |
291 ms |
34300 KB |
Output is correct |
5 |
Correct |
58 ms |
26040 KB |
Output is correct |
6 |
Correct |
12 ms |
18896 KB |
Output is correct |
7 |
Correct |
4 ms |
17748 KB |
Output is correct |