# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299641 | E869120 | Table Tennis (info1cup20_tabletennis) | C++14 | 63 ms | 3948 KiB |
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>
using namespace std;
int N, K;
int A[1 << 18];
bool used[1 << 18];
bool solve(int border) {
for (int i = 0; i < N + K; i++) used[i] = false;
int cl = 0, cr = N + K - 1, cnt = 0;
while (cl < cr && cnt < (N / 2)) {
if (A[cl] + A[cr] > border) cr--;
else if (A[cl] + A[cr] < border) cl++;
else {
used[cl] = true;
used[cr] = true;
cl += 1;
cr -= 1;
cnt += 1;
}
}
if (cnt == (N / 2)) return true;
return false;
}
int main() {
// Step #1. Input
scanf("%d%d", &N, &K);
for (int i = 0; i < N + K; i++) scanf("%d", &A[i]);
sort(A, A + (N + K));
// Step #2. BruteForce
map<long long, int> Map;
vector<long long> Cand, Cand2;
for (int i = 0; i < (K + 2) * 20; i++) {
int t1 = 1000000, t2 = 1000000;
while (t2 < 0 || t2 >= N + K) {
t1 = rand() % (N + K);
t2 = (N - 1 - t1) + (rand() % (2 * K + 1));
}
int val = A[t1] + A[t2];
Map[val] += 1;
Cand2.push_back(val);
}
sort(Cand2.begin(), Cand2.end());
Cand2.erase(unique(Cand2.begin(), Cand2.end()), Cand2.end());
for (int i = 0; i < Cand2.size(); i++) {
//cout << Cand2[i] << " " << Map[Cand2[i]] << endl;
if (Map[Cand2[i]] >= 6) Cand.push_back(Cand2[i]);
}
// Step #3. Tansaku
for (int i = 0; i < Cand.size(); i++) {
bool I = solve(Cand[i]);
if (I == false) continue;
vector<int> vec;
for (int j = 0; j < N + K; j++) {
if (used[j] == true) vec.push_back(A[j]);
}
for (int j = 0; j < vec.size(); j++) {
if (j) printf(" ");
printf("%d", vec[j]);
}
printf("\n");
return 0;
}
return 0;
}
Compilation message (stderr)
# | 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... |