結果

問題 No.275 中央値を求めよ
ユーザー momen999momen999
提出日時 2017-04-12 22:35:11
言語 Haskell
(9.8.2)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 803 bytes
コンパイル時間 6,746 ms
コンパイル使用メモリ 163,804 KB
実行使用メモリ 11,816 KB
最終ジャッジ日時 2023-09-07 06:02:18
合計ジャッジ時間 8,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,492 KB
testcase_01 AC 3 ms
7,368 KB
testcase_02 AC 4 ms
8,616 KB
testcase_03 AC 3 ms
7,508 KB
testcase_04 AC 3 ms
7,388 KB
testcase_05 AC 3 ms
7,476 KB
testcase_06 AC 3 ms
8,360 KB
testcase_07 AC 12 ms
11,536 KB
testcase_08 AC 4 ms
9,532 KB
testcase_09 AC 5 ms
10,016 KB
testcase_10 AC 5 ms
10,244 KB
testcase_11 AC 3 ms
7,304 KB
testcase_12 AC 2 ms
7,260 KB
testcase_13 AC 3 ms
7,260 KB
testcase_14 AC 2 ms
7,208 KB
testcase_15 AC 22 ms
11,740 KB
testcase_16 AC 22 ms
11,816 KB
testcase_17 AC 22 ms
11,764 KB
testcase_18 AC 12 ms
11,452 KB
testcase_19 AC 12 ms
11,640 KB
testcase_20 AC 12 ms
11,504 KB
testcase_21 AC 12 ms
11,564 KB
testcase_22 AC 12 ms
11,656 KB
testcase_23 AC 12 ms
11,464 KB
testcase_24 AC 7 ms
11,536 KB
testcase_25 AC 23 ms
11,688 KB
testcase_26 AC 12 ms
11,624 KB
testcase_27 AC 12 ms
11,544 KB
testcase_28 AC 4 ms
8,428 KB
testcase_29 AC 12 ms
11,520 KB
testcase_30 AC 3 ms
8,488 KB
testcase_31 AC 13 ms
11,588 KB
testcase_32 AC 5 ms
9,832 KB
testcase_33 AC 12 ms
11,628 KB
testcase_34 AC 3 ms
8,456 KB
testcase_35 AC 12 ms
11,616 KB
testcase_36 AC 8 ms
11,552 KB
testcase_37 AC 5 ms
9,828 KB
testcase_38 AC 6 ms
11,232 KB
testcase_39 AC 6 ms
11,436 KB
testcase_40 AC 22 ms
11,576 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

bswap [x] = [x]
bswap (x:y:zs)
    | x < y     = y : bswap (x:zs)
    | otherwise = x : bswap (y:zs)

bsort [] = []
bsort xs = y : bsort ys
    where
        (y:ys) = reverse $ bswap xs

median :: [Int] -> Int -> Double
median [x] _ = fromIntegral (x :: Int) :: Double
median l n   | n `mod` 2 == 0   = l_even (l !! n') (l !! (n' + 1))
             | otherwise        = fromIntegral (l !! n' :: Int) :: Double
    where
        n' = floor $ (fromIntegral (n - 1 :: Int)) / 2.0    -- 小数点以下切り捨て 3.5 -> 3
        l_even x x' = (fromIntegral ((x + x') :: Int)) / 2.0 :: Double

main = do
    str1 <- getLine
    str2 <- getLine
    let
        w = words str2
        n = read str1
        l = map read w :: [Int]
        bl = bsort l :: [Int]
        result = median bl n
    print result
0