#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly
/*
TASK: hidden
LANG: C++11
*/
using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 43
#define INF 1000000000000000000LL
#define mp make_pair
#define add push_back
#define remove pop
int n;
ll values[MAXN];
ll set1[MAXN];
ll set2[MAXN];
int size1, size2;
ll m;
vector<ll> one;
vector<ll> two;
void dfs1(int depth, ll sum) {
if (depth == size1) {
one.add(sum);
return;
}
dfs1(depth + 1, sum + set1[depth]);
dfs1(depth + 1, sum);
}
void dfs2(int depth, ll sum) {
if (depth == size2) {
two.add(sum);
return;
}
dfs2(depth + 1, sum + set2[depth]);
dfs2(depth + 1, sum);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> values[i];
}
for (int i = 0; i < n; i++) {
if (values[i] % 2 == 0) {
set1[size1++] = values[i];
} else {
set2[size2++] = values[i];
}
}
dfs1(0, 0);
dfs2(0, 0);
sort(one.begin(), one.end());
sort(two.begin(), two.end());
//assert(one.size() + two.size() < 5000000);
ll answer = 0;
int twopointer = two.size() - 1;
for (int i = 0; i < (int) (one.size()); i++) {
if (one[i] > m) break;
while (twopointer >= 0 && two[twopointer] > m - one[i]) {
twopointer--;
}
answer += twopointer + 1;
}
cout << answer << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2176 KB |
Output is correct |
2 |
Correct |
0 ms |
2176 KB |
Output is correct |
3 |
Correct |
0 ms |
2176 KB |
Output is correct |
4 |
Correct |
0 ms |
2176 KB |
Output is correct |
5 |
Correct |
0 ms |
2176 KB |
Output is correct |
6 |
Correct |
0 ms |
2176 KB |
Output is correct |
7 |
Correct |
0 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2176 KB |
Output is correct |
2 |
Correct |
0 ms |
2176 KB |
Output is correct |
3 |
Correct |
0 ms |
2176 KB |
Output is correct |
4 |
Correct |
0 ms |
2176 KB |
Output is correct |
5 |
Correct |
0 ms |
2176 KB |
Output is correct |
6 |
Correct |
0 ms |
2176 KB |
Output is correct |
7 |
Correct |
0 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2984 KB |
Output is correct |
2 |
Correct |
0 ms |
2176 KB |
Output is correct |
3 |
Correct |
0 ms |
2176 KB |
Output is correct |
4 |
Correct |
0 ms |
2176 KB |
Output is correct |
5 |
Correct |
0 ms |
2176 KB |
Output is correct |
6 |
Correct |
0 ms |
2176 KB |
Output is correct |
7 |
Correct |
0 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8360 KB |
Output is correct |
2 |
Correct |
249 ms |
26792 KB |
Output is correct |
3 |
Execution timed out |
1000 ms |
199340 KB |
Execution timed out |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
51368 KB |
Output is correct |
2 |
Correct |
16 ms |
4268 KB |
Output is correct |
3 |
Correct |
799 ms |
100780 KB |
Output is correct |
4 |
Correct |
0 ms |
2176 KB |
Output is correct |
5 |
Correct |
56 ms |
14520 KB |
Output is correct |
6 |
Correct |
13 ms |
3752 KB |
Output is correct |
7 |
Correct |
13 ms |
3752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
14764 KB |
Output is correct |
2 |
Correct |
129 ms |
15532 KB |
Output is correct |
3 |
Correct |
86 ms |
10404 KB |
Output is correct |
4 |
Correct |
0 ms |
2176 KB |
Output is correct |
5 |
Correct |
123 ms |
27308 KB |
Output is correct |
6 |
Correct |
443 ms |
51368 KB |
Output is correct |
7 |
Correct |
556 ms |
51628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1000 ms |
198824 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
5548 KB |
Output is correct |
2 |
Correct |
49 ms |
8360 KB |
Output is correct |
3 |
Correct |
13 ms |
3752 KB |
Output is correct |
4 |
Correct |
16 ms |
3880 KB |
Output is correct |
5 |
Correct |
79 ms |
15532 KB |
Output is correct |
6 |
Correct |
53 ms |
8360 KB |
Output is correct |
7 |
Execution timed out |
1000 ms |
395432 KB |
Execution timed out |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
30892 KB |
Output is correct |
2 |
Correct |
19 ms |
4260 KB |
Output is correct |
3 |
Correct |
6 ms |
2984 KB |
Output is correct |
4 |
Execution timed out |
1000 ms |
101548 KB |
Execution timed out |
5 |
Halted |
0 ms |
0 KB |
- |