#include <bits/stdc++.h>
using namespace std;
long long n,m,A[45],cnt=1;
vector<long long> v1, v2;
void dfs(int i, long long v){
if(i > n/2)return;
if(v >= A[i]){
cnt++;
v1.push_back(m-v+A[i]);
dfs(i+1, v-A[i]);
}
dfs(i+1, v);
}
void dfs2(int i, long long v){
if(i > n)return;
if(v >= A[i]){
cnt++;
v2.push_back(m-v+A[i]);
dfs2(i+1, v-A[i]);
}
dfs2(i+1, v);
}
int main(){
cin >> n >> m;
for(int i=1;i<=n;i++)cin >> A[i];
dfs(1, m);
dfs2(n/2+1, m);
sort(v2.begin(), v2.end());
for(int i=0;i<v1.size();i++){
int s =0, e = v2.size()- 1, ans = -1;
while(s <= e){
int mid = s + (e-s)/2;
if(v2[mid] + v1[i] <= m){
s= mid+1;
ans= mid;
}
else e = mid - 1;
}
cnt += ans+1;
}
cout << cnt;
}
Compilation message
bobek.cpp: In function 'int main()':
bobek.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0;i<v1.size();i++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1872 KB |
Output is correct |
2 |
Correct |
65 ms |
5444 KB |
Output is correct |
3 |
Correct |
331 ms |
20796 KB |
Output is correct |
4 |
Correct |
62 ms |
5444 KB |
Output is correct |
5 |
Correct |
8 ms |
1488 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
2760 KB |
Output is correct |
2 |
Correct |
19 ms |
1872 KB |
Output is correct |
3 |
Correct |
148 ms |
10540 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
8 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
3532 KB |
Output is correct |
2 |
Correct |
89 ms |
6608 KB |
Output is correct |
3 |
Correct |
96 ms |
6580 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
41 ms |
6600 KB |
Output is correct |
6 |
Correct |
124 ms |
20736 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
12708 KB |
Output is correct |
2 |
Correct |
18 ms |
1872 KB |
Output is correct |
3 |
Correct |
7 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
4 ms |
940 KB |
Output is correct |
6 |
Correct |
115 ms |
12700 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1960 KB |
Output is correct |
2 |
Correct |
66 ms |
5444 KB |
Output is correct |
3 |
Correct |
8 ms |
940 KB |
Output is correct |
4 |
Correct |
6 ms |
852 KB |
Output is correct |
5 |
Correct |
47 ms |
6600 KB |
Output is correct |
6 |
Correct |
13 ms |
2084 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
250 ms |
20788 KB |
Output is correct |
2 |
Correct |
21 ms |
1872 KB |
Output is correct |
3 |
Correct |
6 ms |
852 KB |
Output is correct |
4 |
Correct |
324 ms |
20884 KB |
Output is correct |
5 |
Correct |
59 ms |
10560 KB |
Output is correct |
6 |
Correct |
7 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |