#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define upb(a, x) upper_bound(a.begin(), a.end(), x)
#define sz size
#define stvr(a) sort(a.begin(), a.end())
using namespace std;
vector<ll int> l, r, rr, l1, v;
ll int m;
int n;
bool lig(int a, int b){ return a&(1<<b); }
int main(){
ios::sync_with_stdio(0);
cin >> n >> m;
for(int i=0;i<n;i++){
int a;
cin >> a;
if(a<=m) v.pb(a);
}
for(int i=0;i<v.sz()/2;i++) l.pb(v[i]);
for(int i=v.sz()/2;i<v.sz();i++)r.pb(v[i]);
for(int mask=0;mask<(1<<l.sz());mask++){
ll int a=0;
for(int i=0;i<l.sz();i++){
if(lig(mask, i)) a+=l[i];
}
if(a<=m) l1.pb(a);
}for(int mask=0;mask<(1<<r.sz());mask++){
ll int a=0;
for(int i=0;i<r.sz();i++){
if(lig(mask, i)) a+=r[i];
}
if(a<=m) rr.pb(a);
}
stvr(rr);
ll int resp=0;
for(int i=0;i<l1.size();i++){
resp+=upb(rr, m-l1[i])-rr.begin();
}
cout << resp << '\n';
return 0;
}
Compilation message
bobek.cpp: In function 'int main()':
bobek.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<v.sz()/2;i++) l.pb(v[i]);
| ~^~~~~~~~~
bobek.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=v.sz()/2;i<v.sz();i++)r.pb(v[i]);
| ~^~~~~~~
bobek.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<l.sz();i++){
| ~^~~~~~~
bobek.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<r.sz();i++){
| ~^~~~~~~
bobek.cpp:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<l1.size();i++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
2004 KB |
Output is correct |
2 |
Correct |
109 ms |
5436 KB |
Output is correct |
3 |
Correct |
537 ms |
20752 KB |
Output is correct |
4 |
Correct |
103 ms |
5416 KB |
Output is correct |
5 |
Correct |
15 ms |
1592 KB |
Output is correct |
6 |
Correct |
8 ms |
976 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
2904 KB |
Output is correct |
2 |
Correct |
34 ms |
2000 KB |
Output is correct |
3 |
Correct |
200 ms |
10492 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
976 KB |
Output is correct |
6 |
Correct |
17 ms |
1512 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
3488 KB |
Output is correct |
2 |
Correct |
157 ms |
6560 KB |
Output is correct |
3 |
Correct |
150 ms |
6588 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
87 ms |
6608 KB |
Output is correct |
6 |
Correct |
298 ms |
20772 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
160 ms |
12712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
1988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
224 ms |
20732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |