結果
| 問題 | No.275 中央値を求めよ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-10 23:24:30 |
| 言語 | Haskell (9.14.1) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 1,000 ms |
| コード長 | 434 bytes |
| 記録 | |
| コンパイル時間 | 2,867 ms |
| コンパイル使用メモリ | 192,384 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2026-03-11 06:38:35 |
| 合計ジャッジ時間 | 3,011 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
module Main where
import Control.Applicative
import Control.Monad
import Data.List (sort)
import Text.Printf (printf)
median :: [Int] -> Double
median as
| r == 0 = (fromIntegral . sum . take 2 $ drop (q - 1) bs) / 2
| otherwise = fromIntegral (bs !! q)
where
bs = sort as
(q, r) = length as `divMod` 2
main :: IO ()
main = do
getLine
as <- fmap read . words <$> getLine
printf "%.1f\n" (median as)