Submission #39234203


Source Code Expand

#include <stdio.h>
#include <string.h>

int i_cmp (void *n1, void *n2) {
	int a = *(int *)n1;
	int b = *(int *)n2;
	if (a > b) {
		return 1;
	} else if (a < b) {
		return -1;
	} else {
		return 0;
	}
}

void swap_all (void *n1, void *n2, size_t size) {
	char tmp[size];
	memcpy(tmp, n1, size);
	memcpy(n1, n2, size);
	memcpy(n2, tmp, size);
}

void heapsort (void *base, size_t num, size_t size, int (* cmpfunc)(void *, void *), int type) {
	for (int i = 1; num > i; i++) {
		for (int j = i; j > 0;) {
			if (type == 1) {
				if (cmpfunc((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2))) == 1) {
					swap_all((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2)), size);
					j = (j - 1) / 2;
				} else {
					break;
				}
			} else {
				if (cmpfunc((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2))) == -1) {
					swap_all((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2)), size);
					j = (j - 1) / 2;
				} else {
					break;
				}
			}
		}
	}

	for (int i = num - 1; i > 0; i--) {
		swap_all((char *)base, (char *)(base + size * i), size);
		for (int j = 0; ;) {
			int lch = 2 * j + 1, rch = 2 * j + 2, rep;
			if (i > rch) {
				if (type == 1) {
					rep = (cmpfunc((char *)(base + size * lch), (char *)(base + size * rch)) == 1 ? lch : rch);
				} else {
					rep = (cmpfunc((char *)(base + size * lch), (char *)(base + size * rch)) == -1 ? lch : rch);
				}
			} else if (rch == i) {
				rep = lch;
			} else {
				break;
			}
			if (type == 1) {
				if (cmpfunc((char *)(base + size * j), (char *)(base + size * rep)) == -1) {
					swap_all((char *)(base + size * j), (char *)(base + size * rep), size);
					j = rep;
				} else {
					break;
				}
			} else {
				if (cmpfunc((char *)(base + size * j), (char *)(base + size * rep)) == 1) {
					swap_all((char *)(base + size * j), (char *)(base + size * rep), size);
					j = rep;
				} else {
					break;
				}
			}
		}
	}
}

int main (void) {
	int n;
	scanf("%i", &n);

	int x[5 * n];
	for (int i = 0; 5 * n > i; i++) {
		scanf("%i", &x[i]);
	}

	heapsort(x, 5 * n, sizeof(int), i_cmp, 1);

	/*
	for (int i = 0; 5 * n > i; i++) {
		printf("%i ", x[i]);
	}
	printf("\n");
	// */

	int sum = 0;
	for (int i = 0; 3 * n > i; i++) {
		sum += x[n + i];
	}
	double ans = (double)sum / (3 * n);
	printf("%f", ans);

	return 0;
}

Submission Info

Submission Time
Task B - Trimmed Mean
User InTheBloom
Language C (Clang 10.0.0)
Score 200
Code Size 2447 Byte
Status AC
Exec Time 6 ms
Memory 2148 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 23
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt
Case Name Status Exec Time Memory
example_00.txt AC 6 ms 2068 KiB
example_01.txt AC 1 ms 2072 KiB
hand_00.txt AC 1 ms 2032 KiB
hand_01.txt AC 1 ms 1992 KiB
hand_02.txt AC 2 ms 2048 KiB
hand_03.txt AC 1 ms 1976 KiB
hand_04.txt AC 2 ms 2088 KiB
hand_05.txt AC 1 ms 2040 KiB
random_00.txt AC 1 ms 2068 KiB
random_01.txt AC 1 ms 2148 KiB
random_02.txt AC 2 ms 1972 KiB
random_03.txt AC 2 ms 2068 KiB
random_04.txt AC 6 ms 1992 KiB
random_05.txt AC 1 ms 2048 KiB
random_06.txt AC 2 ms 1976 KiB
random_07.txt AC 1 ms 2044 KiB
random_08.txt AC 2 ms 2048 KiB
random_09.txt AC 1 ms 2036 KiB
random_10.txt AC 1 ms 1980 KiB
random_11.txt AC 1 ms 2072 KiB
random_12.txt AC 2 ms 1988 KiB
random_13.txt AC 1 ms 2072 KiB
random_14.txt AC 1 ms 2088 KiB