This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
}
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];
}
}
dfs1(0, 0);
dfs2(0, 0);
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++) {
while (twopointer < (int) (two.size()) && one[i] + two[twopointer] <= m) {
twopointer++;
}
answer += twopointer;
}
cout << answer << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |