結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー k.h
提出日時 2019-08-04 23:17:47
言語 Go
(1.26.1)
コンパイル:
env GOCACHE=/tmp go build _filename_
実行:
./Main
結果
AC  
実行時間 1 ms / 1,000 ms
+ 617µs
コード長 461 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 13,299 ms
コンパイル使用メモリ 279,272 KB
実行使用メモリ 9,416 KB
最終ジャッジ日時 2026-08-15 23:51:56
合計ジャッジ時間 12,694 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())
	nums := make([]int, N)
	var t int
	for i := range nums {
		sc.Scan()
		t, _ = strconv.Atoi(sc.Text())
		nums[i] = t
	}
	sort.Ints(nums)
	l := len(nums)
	if l%2 == 0 {
		fmt.Println((float64(nums[l/2-1]) + float64(nums[l/2])) / 2)
	} else {
		fmt.Println(nums[(l-1)/2])
	}
}
0