結果

問題 No.275 中央値を求めよ
ユーザー lvs7k
提出日時 2018-09-10 23:24:30
言語 Haskell
(9.10.1)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 434 bytes
コンパイル時間 4,972 ms
コンパイル使用メモリ 173,440 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-06-25 01:57:00
合計ジャッジ時間 6,221 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

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)
0