結果

問題 No.702 中央値を求めよ LIMITED
ユーザー bal4u
提出日時 2019-05-05 17:13:38
言語 C
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 1,106 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 29,056 KB
実行使用メモリ 40,960 KB
最終ジャッジ日時 2024-06-25 06:15:56
合計ジャッジ時間 26,820 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 2
other MLE * 25
権限があれば一括ダウンロードができます

ソースコード

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;
}

#if 0
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];
}
#endif

#define H 6002000
#define HALF (unsigned)2150000000
unsigned a[H+100]; int sz;

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

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

	scanf("%d", &seed); 
    x = seed;
	for (i = 0; i < 10000001; i++) {
		k = generate();
		if (k <= HALF) a[sz++] = k;
	}
	qsort(a, sz, sizeof(unsigned), cmp);
#if 0
	printf("%u\n", selection(a, sz, 5000000));
#else
	printf("%u\n", a[5000000]);
#endif
    return 0;
}
0