제출 #826533

#제출 시각아이디문제언어결과실행 시간메모리
826533rainboyTable Tennis (info1cup20_tabletennis)C11
100 / 100
2332 ms20300 KiB
#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 add(int k) {
	int h = hash(k), o;

	for (o = eo[h]; o--; )
		if (ek[h][o] == k)
			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] = 0;
}

int incr(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--)
			add(aa[i] + aa[j]);
	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++)
			if (incr(s = aa[i] + aa[j]) == 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;
			}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

tabletennis.c: In function 'add':
tabletennis.c:33:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   33 |  if (o >= 2 && (o & o - 1) == 0) {
      |                     ~~^~~
tabletennis.c: In function 'main':
tabletennis.c:55:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
tabletennis.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...