結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー FF256grhy
提出日時 2015-09-04 22:36:32
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 520 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 175 ms
コンパイル使用メモリ 41,124 KB
実行使用メモリ 48,484 KB
最終ジャッジ日時 2026-04-02 13:15:44
合計ジャッジ時間 1,390 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int n, a[2001];

int main(void) {
	scanf("%d", &n);
	int i;
	for(i = 0; i < n; i++) {
		int temp;
		scanf("%d", &temp);
		a[temp + 1000]++;
	}
	
	int c = 0, flag = 0, ans = 0;
	for(i = 0; i < 2001; i++) {
		if(a[i]) {
			c += a[i];
			if(n % 2) {
				if(c > n / 2) {
					ans = 2 * (i - 1000);
					break;
				}
			} else {
				if(c >= n / 2) {
					ans += i - 1000;
					if( ! flag) {
						flag = 1;
					} else {
						break;
					}
				}
			}
		}
	}
	
	printf("%f\n", ans / 2.0 );
	
	return 0;
}
0