Submission #826241

# Submission time Handle Problem Language Result Execution time Memory
826241 2023-08-15T11:28:44 Z rainboy Table Tennis (info1cup20_tabletennis) C
9 / 100
3000 ms 2100 KB
#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[N + K];
	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;
}

Compilation message

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
1 Incorrect 0 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 852 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 57 ms 880 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 596 KB Output is correct
2 Execution timed out 3066 ms 2100 KB Time limit exceeded
3 Halted 0 ms 0 KB -