結果

問題 No.702 中央値を求めよ LIMITED
ユーザー 37zigen37zigen
提出日時 2020-03-19 02:54:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,530 ms / 5,000 ms
コード長 1,159 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 68,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 21:54:50
合計ジャッジ時間 40,904 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,488 ms
4,376 KB
testcase_01 AC 1,156 ms
4,376 KB
testcase_02 AC 1,402 ms
4,384 KB
testcase_03 AC 1,322 ms
4,376 KB
testcase_04 AC 1,518 ms
4,380 KB
testcase_05 AC 1,521 ms
4,376 KB
testcase_06 AC 1,206 ms
4,380 KB
testcase_07 AC 1,216 ms
4,380 KB
testcase_08 AC 1,415 ms
4,376 KB
testcase_09 AC 1,484 ms
4,380 KB
testcase_10 AC 1,370 ms
4,376 KB
testcase_11 AC 1,161 ms
4,380 KB
testcase_12 AC 1,474 ms
4,380 KB
testcase_13 AC 1,379 ms
4,380 KB
testcase_14 AC 1,472 ms
4,380 KB
testcase_15 AC 1,477 ms
4,380 KB
testcase_16 AC 1,131 ms
4,376 KB
testcase_17 AC 1,401 ms
4,380 KB
testcase_18 AC 1,411 ms
4,380 KB
testcase_19 AC 1,503 ms
4,376 KB
testcase_20 AC 1,494 ms
4,380 KB
testcase_21 AC 1,501 ms
4,376 KB
testcase_22 AC 1,348 ms
4,380 KB
testcase_23 AC 1,530 ms
4,380 KB
testcase_24 AC 1,530 ms
4,384 KB
testcase_25 AC 1,522 ms
4,380 KB
testcase_26 AC 1,079 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

long long c1 = 0, c2 = 0, c3 = 0;
long long x = 0, y = 1, z = 2, w = 3;
long long seed;


void initialize() {
	x = seed;
	y = 1;
	z = 2;
	w = 3;
	c1 = 0;
	c2 = 0;
	c3 = 0;
}

long long generate() {
	long long t = (x ^ (x << 11)) & ((1L << 32) - 1);
	x = y & ((1L << 32) - 1);
	y = z & ((1L << 32) - 1);
	z = w & ((1L << 32) - 1);
	w = ((w ^ (w >> 19)) ^ (t ^ (t >> 8))) & ((1L << 32) - 1);
	return w;
}


int main() {
    std::cin >> seed;
	initialize();
	int n = 10000001;
	int a[1 << 16];
	for (int i = 0; i < 10000001; ++i) {
		++a[(int) (generate() >> 16)];
	}
	int sum = 0;
	int p = 0;
	while (sum < 5000001) {
		sum += a[p];
		++p;
	}
	p = p - 1;
	long long gt = std::max(0LL, (1LL << 16) * (p - 1)), el = std::min((long long) (1LL << 16) * (p + 1), (1LL << 32) - 1);
	while (true) {
		long long m = (gt + el) / 2;
		initialize();
		for (int i = 0; i < 10000001; ++i) {
			generate();
			if (w < m)
				++c1;
			else if (w == m)
				++c2;
			else
				++c3;
		}
			if (c1 + c2 < 5000001) {
			gt = m;
		} else {
			el = m;
		}
		if (c1 + c2 >= 5000001 && c2 + c3 >= 5000001) {
			std::cout << m << std::endl;
			return 0;
		}
	}
}


0