結果

問題 No.275 中央値を求めよ
ユーザー bal4u
提出日時 2019-04-14 14:32:12
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 897 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 28,544 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 00:03:46
合計ジャッジ時間 1,377 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.275 中央値を求めよ
// 2019.4.14 bal4u

#include <stdio.h>
#include <stdlib.h>

//// 高速入力
#if 0
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()   // 整数の入力(負数に対応)
{
	int n = 0, c = gc();
	if (c == '-') {
		c = gc();
		do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int N;
int a[1005];

int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

int main()
{
	int i, s;
	N = in();
	for (i = 0; i < N; i++) a[i] = in();
	qsort(a, N, sizeof(int), cmp);
	if (N & 1) printf("%d\n", a[N / 2]);
	else {
		s = a[N/2 - 1] + a[N/2];
		if ((s & 1) == 0) printf("%d\n", s / 2);
		else if (s == -1) puts("-0.5");
		else printf("%d.5\n", s / 2);
	}
	return 0;
}
0