結果

問題 No.149 碁石の移動
ユーザー 情報学生
提出日時 2019-08-29 10:36:17
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 181,008 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 16:49:05
合計ジャッジ時間 2,090 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

import Control.Applicative ((<$>))
import Data.Char (isSpace)
import Data.List (unfoldr)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

getL :: (ByteString -> [Int]) -> IO [Int]
getL f = f <$> B.getContents

readIL :: (ByteString -> Maybe (Int, ByteString)) -> (ByteString -> [Int])
readIL f = unfoldr g
    where
        g s = do
            (n, s') <- f s
            return (n, B.dropWhile isSpace s')

main :: IO ()
main = print =<< solve <$> getL (readIL B.readInt)

solve :: [Int] -> Int
solve [aw, ab, bw, bb, c, d]
    | c <= ab && d >= bw            = aw + bw
    | c <= ab && d < bw             = aw + d
    | c > ab  && d >= (bw + c - ab) = aw + bw 
    | c > ab  && d < (bw + c - ab)  = (aw - (c - ab)) + d
    | otherwise                     = 0
0