結果

問題 No.702 中央値を求めよ LIMITED
ユーザー 37zigen37zigen
提出日時 2018-06-16 01:02:59
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,537 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 74,692 KB
実行使用メモリ 62,924 KB
最終ジャッジ日時 2023-09-13 05:39:52
合計ジャッジ時間 11,895 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() throws FileNotFoundException {
		int shift = 1000;

		Scanner sc = new Scanner(System.in);
		seed = sc.nextInt();
		int[] a = new int[1 << 16];
		for (int i = 0; i < 10000001; ++i) {
			++a[(int) (generate() >> 16)];
		}
		int sum = 0;
		int p = 0;
		while (sum < 10000001 / 2) {
			sum += a[p];
			++p;
		}

		long gt = Math.max(0, (1 << 16) * (p - 1)), el = Math.min((long) (1 << 16) * (p + 1), Integer.MAX_VALUE);
		while (true) {
			int m = (int) ((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) {
				el = m;
			} else {
				gt = m;
			}

			if (c1 + c2 >= 5000001 && c2 + c3 >= 5000001) {
				System.out.println(m);
				return;
			}
		}
	}

	long c1 = 0, c2 = 0, c3 = 0;

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

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

	long generate() {
		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;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0