結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
yutasth
|
| 提出日時 | 2017-05-04 16:23:25 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 1,000 ms |
| コード長 | 452 bytes |
| コンパイル時間 | 9,211 ms |
| コンパイル使用メモリ | 171,904 KB |
| 実行使用メモリ | 8,320 KB |
| 最終ジャッジ日時 | 2024-06-25 00:29:25 |
| 合計ジャッジ時間 | 3,248 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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
ソースコード
import Prelude
import Data.List (sort, genericLength)
main :: IO ()
main = do
n <- read <$> getLine
as <- map read . words <$> getLine
print $ calc n as
calc :: Int -> [Int] -> Float
calc n as = let as' = sort as
in if odd n then fromIntegral $ as' !! div n 2
else average $ take 2 $ drop (div n 2 - 1) as'
average :: (Real a, Fractional b) => [a] -> b
average is = realToFrac (sum is) / genericLength is
yutasth