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 <stdio.h>
#include <stdlib.h>
#define N 150000
#define K 400
#define M 200000
#define MD 0x7fffffff
int max(int a, int b) { return a > b ? a : b; }
int *ek[M], *ev[M], eo[M], X = 123454321;
void init() {
int h;
for (h = 0; h < M; h++) {
ek[h] = (int *) malloc(2 * sizeof *ek[h]);
ev[h] = (int *) malloc(2 * sizeof *ev[h]);
}
}
int hash(int k) {
return ((long long) k * X % MD) % M;
}
void put(int k, int v) {
int h = hash(k), o;
for (o = eo[h]; o--; )
if (ek[h][o] == k) {
ev[h][o] = v;
return;
}
o = eo[h]++;
if (o >= 2 && (o & o - 1) == 0) {
ek[h] = (int *) realloc(ek[h], o * 2 * sizeof *ek[h]);
ev[h] = (int *) realloc(ev[h], o * 2 * sizeof *ev[h]);
}
ek[h][o] = k, ev[h][o] = v;
}
int get(int k) {
int h = hash(k), o;
for (o = eo[h]; o--; )
if (ek[h][o] == k)
return ev[h][o];
return 0;
}
int main() {
static int aa[N + K];
static char used[N + K];
int n, k, i, j, s, cnt;
init();
scanf("%d%d", &n, &k);
for (i = 0; i < n + k; i++)
scanf("%d", &aa[i]);
for (i = 0; i <= k; i++)
for (j = n + k - 1; j > i && j >= n - 1; j--)
put(aa[i] + aa[j], 0);
for (i = 0; i < n + k; i++)
for (j = max(n - 1 - i, i + 1); j < n + k && i + j <= n - 1 + k * 2; j++) {
s = aa[i] + aa[j];
put(s, cnt = get(s) + 1);
if (cnt == n / 2) {
for (i = 0, j = n + k - 1, cnt = 0; i < j && cnt < n / 2; i++) {
while (i < j && aa[i] + aa[j] > s)
j--;
if (i < j && aa[i] + aa[j] == s)
used[i] = used[j] = 1, cnt--;
}
for (i = 0; i < n + k; i++)
if (used[i])
printf("%d ", aa[i]);
printf("\n");
}
}
return 0;
}
Compilation message (stderr)
tabletennis.c: In function 'put':
tabletennis.c:35:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
35 | if (o >= 2 && (o & o - 1) == 0) {
| ~~^~~
tabletennis.c: In function 'main':
tabletennis.c:57:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
tabletennis.c:59:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |