結果

問題 No.609 Noelちゃんと星々
ユーザー okadukiokaduki
提出日時 2017-12-09 01:35:02
言語 Haskell
(9.8.2)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 9,193 ms
コンパイル使用メモリ 180,296 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2024-05-07 07:25:45
合計ジャッジ時間 15,193 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 228 ms
12,288 KB
testcase_01 AC 118 ms
11,264 KB
testcase_02 AC 84 ms
10,752 KB
testcase_03 AC 107 ms
11,008 KB
testcase_04 AC 56 ms
9,728 KB
testcase_05 AC 302 ms
17,536 KB
testcase_06 AC 244 ms
12,544 KB
testcase_07 AC 145 ms
11,392 KB
testcase_08 AC 34 ms
8,960 KB
testcase_09 AC 92 ms
10,752 KB
testcase_10 AC 182 ms
11,776 KB
testcase_11 AC 172 ms
11,904 KB
testcase_12 AC 209 ms
11,776 KB
testcase_13 AC 43 ms
9,216 KB
testcase_14 AC 19 ms
8,576 KB
testcase_15 AC 260 ms
12,672 KB
testcase_16 AC 304 ms
17,536 KB
testcase_17 AC 231 ms
12,416 KB
testcase_18 AC 82 ms
10,624 KB
testcase_19 AC 248 ms
12,544 KB
testcase_20 AC 307 ms
13,440 KB
testcase_21 AC 308 ms
13,440 KB
testcase_22 AC 313 ms
13,440 KB
testcase_23 AC 311 ms
13,440 KB
testcase_24 AC 309 ms
13,568 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

f ys y = foldl (\a b -> a + abs (y-b)) 0 ys

main = do
  _ <- getInts
  xs <- getInts
  print $ tri (f xs) (-1000000010) 1000000010

-- util
getInts :: IO [Integer]
getInts = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine

tri f lb ub
  | ub-lb < 3 = minimum [f x | x <- [lb .. ub]]
  | otherwise = if y1 < y2 then tri f lb x2
                else tri f x1 ub
  where
    (x1,x2) = ((lb*2 + ub) `div` 3, (lb + ub*2) `div` 3)
    (y1,y2) = (f x1, f x2)
0