結果

問題 No.275 中央値を求めよ
ユーザー nobsunnobsun
提出日時 2018-06-17 16:58:05
言語 Haskell
(9.10.1)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 768 bytes
コンパイル時間 2,806 ms
コンパイル使用メモリ 171,264 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-06-25 01:40:31
合計ジャッジ時間 4,462 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 Data.List
main :: IO ()
main = do
{ [n] <- getInts
; xs <- getInts
; print $ av $ snd3 $ foldl f ([],[],[]) xs
}
where
f y x = case y of
(ls,[m],rs)
| x < m -> case insertBy (flip compare) x ls of
l:ls' -> (ls',[l,m],rs)
| otherwise -> case insert x rs of
r:rs' -> (ls,[m,r],rs')
(ls,[m,n],rs)
| x < m -> (insertBy (flip compare) x ls,[m],n:rs)
| x < n -> (m:ls,[x],n:rs)
| otherwise -> (m:ls,[n],insert x rs)
(_,[],_) -> ([],[x],[])
getInts :: IO [Int]
getInts = map read . words <$> getLine
snd3 :: (a,b,c) -> b
snd3 (_,b,_) = b
av :: [Int] -> Double
av [x] = fromIntegral x
av [x,y] = fromIntegral (x + y) / 2
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0