結果

問題 No.702 中央値を求めよ LIMITED
ユーザー c-yanc-yan
提出日時 2021-02-17 02:14:46
言語 Go
(1.22.1)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 1,254 bytes
コンパイル時間 10,585 ms
コンパイル使用メモリ 211,820 KB
実行使用メモリ 5,488 KB
最終ジャッジ日時 2023-08-14 22:01:19
合計ジャッジ時間 14,337 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var (
	x uint32 = 0
	y uint32 = 1
	z uint32 = 2
	w uint32 = 3
)

func xorshift() uint32 {
	var t uint32 = x ^ (x << 11)
	x = y
	y = z
	z = w
	w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))
	return w
}

const (
	totalCount = 10000001
	l          = (1 << 31) - (1<<31)/100
	r          = (1 << 31) + (1<<31)/100
)

func main() {
	defer flush()

	x = uint32(readInt())

	t := make([]int, 0, totalCount/100)
	c := 0
	for i := 0; i < totalCount; i++ {
		a := int(xorshift())
		if a < l {
			c++
		} else if a < r {
			t = append(t, a)
		}
	}
	sort.Ints(t)
	println(t[totalCount/2-c])
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}
0