#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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> values[i];
}
sort(values, values + n);
for (int i = 0; i < n; i++) {
//cin >> values[i];
if (values[i] % 2 == 0) {
set1[size1++] = values[i];
} else {
set2[size2++] = values[i];
}
}
sort(set1, set1 + size1);
sort(set2, set2 + size2);
for (int i = 0; i < (1 << size1); i++) {
ll sum = 0;
for (int j = 0; j < size1; j++) {
if (i & (1 << j)) {
sum += set1[j];
}
}
one.add(sum);
}
for (int i = 0; i < (1 << size2); i++) {
ll sum = 0;
for (int j = 0; j < size2; j++) {
if (i & (1 << j)) {
sum += set2[j];
}
}
two.add(sum);
}
sort(one.rbegin(), one.rend());
sort(two.begin(), two.end());
assert(one.size() + two.size() < 5000000);
ll answer = 0;
//int twopointer = 0;
for (int i = 0; i < (int) (one.size()); i++) {
int start = 0;
int end = two.size() - 1;
while (start <= end) {
int mid = (start + end) / 2;
if (one[i] + two[mid] <= m) {
start = mid + 1;
} else {
end = mid - 1;
}
}
answer += start;
/*
while (twopointer < (int) (two.size()) && one[i] + two[twopointer] <= m) {
twopointer++;
}
answer += twopointer;*/
}
cout << answer << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2180 KB |
Output is correct |
2 |
Correct |
0 ms |
2180 KB |
Output is correct |
3 |
Correct |
0 ms |
2180 KB |
Output is correct |
4 |
Correct |
0 ms |
2180 KB |
Output is correct |
5 |
Correct |
0 ms |
2180 KB |
Output is correct |
6 |
Correct |
0 ms |
2180 KB |
Output is correct |
7 |
Correct |
0 ms |
2180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2180 KB |
Output is correct |
2 |
Correct |
0 ms |
2180 KB |
Output is correct |
3 |
Correct |
0 ms |
2180 KB |
Output is correct |
4 |
Correct |
0 ms |
2180 KB |
Output is correct |
5 |
Correct |
0 ms |
2180 KB |
Output is correct |
6 |
Correct |
0 ms |
2180 KB |
Output is correct |
7 |
Correct |
0 ms |
2180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2988 KB |
Output is correct |
2 |
Correct |
0 ms |
2180 KB |
Output is correct |
3 |
Correct |
0 ms |
2180 KB |
Output is correct |
4 |
Correct |
0 ms |
2180 KB |
Output is correct |
5 |
Correct |
0 ms |
2180 KB |
Output is correct |
6 |
Correct |
0 ms |
2180 KB |
Output is correct |
7 |
Correct |
0 ms |
2180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
8364 KB |
Output is correct |
2 |
Correct |
459 ms |
26796 KB |
Output is correct |
3 |
Execution timed out |
1000 ms |
199344 KB |
Execution timed out |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
819 ms |
51372 KB |
Output is correct |
2 |
Correct |
36 ms |
4272 KB |
Output is correct |
3 |
Execution timed out |
1000 ms |
100784 KB |
Execution timed out |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
14768 KB |
Output is correct |
2 |
Correct |
226 ms |
15536 KB |
Output is correct |
3 |
Correct |
179 ms |
10408 KB |
Output is correct |
4 |
Correct |
0 ms |
2180 KB |
Output is correct |
5 |
Correct |
273 ms |
27312 KB |
Output is correct |
6 |
Correct |
926 ms |
51372 KB |
Output is correct |
7 |
Correct |
763 ms |
51632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
198828 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
5552 KB |
Output is correct |
2 |
Correct |
106 ms |
8364 KB |
Output is correct |
3 |
Correct |
26 ms |
3756 KB |
Output is correct |
4 |
Correct |
23 ms |
3884 KB |
Output is correct |
5 |
Correct |
146 ms |
15536 KB |
Output is correct |
6 |
Correct |
113 ms |
8364 KB |
Output is correct |
7 |
Execution timed out |
1000 ms |
395436 KB |
Execution timed out |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
506 ms |
30896 KB |
Output is correct |
2 |
Correct |
36 ms |
4264 KB |
Output is correct |
3 |
Correct |
19 ms |
2988 KB |
Output is correct |
4 |
Execution timed out |
1000 ms |
101552 KB |
Execution timed out |
5 |
Halted |
0 ms |
0 KB |
- |