結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
yutasth
|
| 提出日時 | 2017-05-04 16:14:06 |
| 言語 | Haskell (9.10.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 448 bytes |
| コンパイル時間 | 1,711 ms |
| コンパイル使用メモリ | 174,336 KB |
| 実行使用メモリ | 8,064 KB |
| 最終ジャッジ日時 | 2024-09-14 07:07:42 |
| 合計ジャッジ時間 | 2,980 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 21 WA * 17 |
コンパイルメッセージ
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] -> Double
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) as
average :: (Real a, Fractional b) => [a] -> b
average is = realToFrac (sum is) / genericLength is
yutasth