이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 150000
#define K 400
#define M ((K + 1) * (K + 1))
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(int *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] < a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int main() {
static int aa[N + K], ss[M], kk[M];
static char used[M];
int n, m, k, h, i, j, s;
scanf("%d%d", &n, &k);
for (i = 0; i < n + k; i++)
scanf("%d", &aa[i]);
m = 0;
for (i = 0; i <= k; i++)
for (j = n + k - 1; j > i && j >= n - 1; j--)
ss[m++] = aa[i] + aa[j];
sort(ss, 0, m);
for (i = 0; i < n; i++)
for (j = max(n - 1 - i, i + 1), h = 0; j < n && i + j <= n - 1 + k * 2; j++) {
s = aa[i] + aa[j];
while (h < m && ss[h] < s)
h++;
if (h < m && ss[h] == s)
kk[h]++;
}
for (h = 0; h < m; h++)
if (kk[h] >= n / 2) {
for (i = 0, j = n + k - 1, k = n / 2; i < j && k > 0; i++) {
while (i < j && aa[i] + aa[j] > ss[h])
j--;
if (i < j && aa[i] + aa[j] == ss[h])
used[i] = used[j] = 1, k--;
}
for (i = 0; i < n + k; i++)
if (used[i])
printf("%d ", aa[i]);
printf("\n");
return 0;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tabletennis.c: In function 'main':
tabletennis.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
tabletennis.c:41:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | 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... |