結果

問題 No.702 中央値を求めよ LIMITED
ユーザー bal4ubal4u
提出日時 2019-05-05 18:05:10
言語 C
(gcc 12.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,105 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 21:04:50
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
5,248 KB
testcase_01 AC 60 ms
5,376 KB
testcase_02 AC 60 ms
5,376 KB
testcase_03 AC 62 ms
5,376 KB
testcase_04 AC 61 ms
5,376 KB
testcase_05 AC 60 ms
5,376 KB
testcase_06 AC 62 ms
5,376 KB
testcase_07 AC 62 ms
5,376 KB
testcase_08 AC 62 ms
5,376 KB
testcase_09 AC 63 ms
5,376 KB
testcase_10 AC 63 ms
5,376 KB
testcase_11 AC 63 ms
5,376 KB
testcase_12 AC 61 ms
5,376 KB
testcase_13 AC 62 ms
5,376 KB
testcase_14 AC 61 ms
5,376 KB
testcase_15 AC 61 ms
5,376 KB
testcase_16 AC 62 ms
5,376 KB
testcase_17 AC 61 ms
5,376 KB
testcase_18 AC 61 ms
5,376 KB
testcase_19 AC 61 ms
5,376 KB
testcase_20 AC 61 ms
5,376 KB
testcase_21 AC 61 ms
5,376 KB
testcase_22 AC 62 ms
5,376 KB
testcase_23 AC 62 ms
5,376 KB
testcase_24 AC 63 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 64 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No. 702 中央値を求めよ LIMITED
// 2019.5.5 bal4u

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

unsigned x = 0, y = 1, z = 2, w = 3;
unsigned generate() { 
    unsigned t = x^(x<<11);
    x = y, y = z, z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    return w;
}

unsigned selection(unsigned *a, int sz, int n) {
	int i, j, l, r;
	unsigned p, t;
	l = 0, r = sz-1;
	while (l < r) {
		p = a[(l+r)/2];
		i = l-1, j = r+1;
		while (1) {
			while (a[++i] < p);
			while (a[--j] > p);
			if (i > j) break;
			t = a[i], a[i] = a[j], a[j] = t;
		}
		if (n < i) r = j;
		if (n > j) l = i;
	}
	return a[n];
}

#define SIZE 10000001
#define UPPER (unsigned)2150000000
#define LOWER (unsigned)2140000000
unsigned a[SIZE>>1]; int sz;

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

int main()
 {
    int i, seed, cnt;
	unsigned k;

	scanf("%d", &seed); 
    x = seed;
	sz = 0, cnt = 0; for (i = 0; i < SIZE; i++) {
		k = generate();
		if (k <= LOWER) cnt++;
		else if (k < UPPER) a[sz++] = k;
	}
	printf("%u\n", selection(a, sz, (SIZE >> 1)-cnt));
    return 0;
}
0