結果

問題 No.702 中央値を求めよ LIMITED
ユーザー e869120e869120
提出日時 2018-06-08 23:45:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 843 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 75,224 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 21:04:52
合計ジャッジ時間 4,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

unsigned int x, y, z, w;
int counts[1 << 16], n = 10000001, seed;

void init() {
	x = seed; y = 1; z = 2; w = 3;
}

unsigned int generate() {
	unsigned int t = (x ^ (x << 11));
	x = y;
	y = z;
	z = w;
	w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
	return w;
}

int main() {
	cin >> seed; init();
	for (int i = 0; i < n; i++) {
		unsigned int T = generate();
		counts[T / (1 << 16)]++;
	}
	unsigned int s = 0, mid = 0, K = 0;
	for (int i = 0; i < n; i++) {
		if (s + counts[i] > n / 2) { mid = i; K = n / 2 - s; break; }
		s += counts[i];
	}
	vector<unsigned int>F; init();
	for (int i = 0; i < n; i++) {
		unsigned int T = generate();
		if ((mid << 16) <= T && T < ((mid + 1) << 16)) { F.push_back(T); }
	}
	sort(F.begin(), F.end());
	cout << F[K] << endl;
	return 0;
}
0