//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4 + 5;
const ll INF = 1e18 + 5;
const ll mod = 1e6 + 7;
const int tx[] = {1, -1, 0, 0}, ty[] = {0, 0, 1, -1};
const ll bs = 31;
int n;
ll m;
ll a[45], ans;
vector <ll> vec;
main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int nn = n / 2;
for (int mask = 0; mask < (1 << nn); mask++) {
ll res = 0;
for (int i = 0; i < nn; i++) {
if ((mask >> i) & 1) {
res += a[i + 1];
}
}
vec.push_back(res);
}
sort(vec.begin(), vec.end());
for (int mask = 0; mask < (1 << (n - nn)); mask++) {
ll res = 0;
for (int i = 0; i < n - nn; i++) {
if ((mask >> i) & 1) {
res += a[i + nn + 1];
}
}
ll it = upper_bound(vec.begin(), vec.end(), m - res) - vec.begin();
ans += it;
}
cout << ans;
return 0;
}
/**
5
1 2 1 1 1
*/
Compilation message
bobek.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
1020 KB |
Output is correct |
2 |
Correct |
102 ms |
2548 KB |
Output is correct |
3 |
Correct |
562 ms |
8784 KB |
Output is correct |
4 |
Correct |
102 ms |
2548 KB |
Output is correct |
5 |
Correct |
19 ms |
1020 KB |
Output is correct |
6 |
Correct |
10 ms |
768 KB |
Output is correct |
7 |
Correct |
16 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
1528 KB |
Output is correct |
2 |
Correct |
37 ms |
1020 KB |
Output is correct |
3 |
Correct |
214 ms |
4592 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
768 KB |
Output is correct |
6 |
Correct |
22 ms |
1144 KB |
Output is correct |
7 |
Correct |
18 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
1528 KB |
Output is correct |
2 |
Correct |
175 ms |
2548 KB |
Output is correct |
3 |
Correct |
173 ms |
2696 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
97 ms |
2548 KB |
Output is correct |
6 |
Correct |
264 ms |
8740 KB |
Output is correct |
7 |
Correct |
83 ms |
2548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
388 ms |
4556 KB |
Output is correct |
2 |
Correct |
29 ms |
1020 KB |
Output is correct |
3 |
Correct |
12 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
10 ms |
768 KB |
Output is correct |
6 |
Correct |
234 ms |
4724 KB |
Output is correct |
7 |
Correct |
18 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
1020 KB |
Output is correct |
2 |
Correct |
110 ms |
2548 KB |
Output is correct |
3 |
Correct |
11 ms |
768 KB |
Output is correct |
4 |
Correct |
11 ms |
768 KB |
Output is correct |
5 |
Correct |
138 ms |
2548 KB |
Output is correct |
6 |
Correct |
25 ms |
1020 KB |
Output is correct |
7 |
Correct |
269 ms |
8668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
444 ms |
8692 KB |
Output is correct |
2 |
Correct |
36 ms |
1020 KB |
Output is correct |
3 |
Correct |
11 ms |
640 KB |
Output is correct |
4 |
Correct |
561 ms |
8608 KB |
Output is correct |
5 |
Correct |
146 ms |
4584 KB |
Output is correct |
6 |
Correct |
17 ms |
1020 KB |
Output is correct |
7 |
Correct |
32 ms |
1584 KB |
Output is correct |