結果
| 問題 |
No.609 Noelちゃんと星々
|
| コンテスト | |
| ユーザー |
okaduki
|
| 提出日時 | 2017-12-09 01:35:02 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 333 ms / 2,000 ms |
| コード長 | 679 bytes |
| コンパイル時間 | 10,464 ms |
| コンパイル使用メモリ | 180,212 KB |
| 実行使用メモリ | 17,536 KB |
| 最終ジャッジ日時 | 2024-11-29 22:16:25 |
| 合計ジャッジ時間 | 16,957 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
コンパイルメッセージ
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
ソースコード
{-# 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)
okaduki