結果

問題 No.609 Noelちゃんと星々
ユーザー okadukiokaduki
提出日時 2017-12-09 01:35:02
言語 Haskell
(9.8.2)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 9,514 ms
コンパイル使用メモリ 161,472 KB
実行使用メモリ 21,184 KB
最終ジャッジ日時 2023-08-20 00:04:02
合計ジャッジ時間 16,356 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 252 ms
18,532 KB
testcase_01 AC 133 ms
14,372 KB
testcase_02 AC 93 ms
13,696 KB
testcase_03 AC 122 ms
14,292 KB
testcase_04 AC 63 ms
12,804 KB
testcase_05 AC 313 ms
19,784 KB
testcase_06 AC 272 ms
19,248 KB
testcase_07 AC 163 ms
14,376 KB
testcase_08 AC 43 ms
12,152 KB
testcase_09 AC 102 ms
14,012 KB
testcase_10 AC 192 ms
14,488 KB
testcase_11 AC 182 ms
14,116 KB
testcase_12 AC 232 ms
17,956 KB
testcase_13 AC 53 ms
12,424 KB
testcase_14 AC 32 ms
11,760 KB
testcase_15 AC 272 ms
19,572 KB
testcase_16 AC 313 ms
20,108 KB
testcase_17 AC 252 ms
18,584 KB
testcase_18 AC 92 ms
13,576 KB
testcase_19 AC 273 ms
19,264 KB
testcase_20 AC 343 ms
21,028 KB
testcase_21 AC 343 ms
21,108 KB
testcase_22 AC 332 ms
21,184 KB
testcase_23 AC 342 ms
21,048 KB
testcase_24 AC 333 ms
21,168 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 #

{-# 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