結果

問題 No.149 碁石の移動
ユーザー 情報学生情報学生
提出日時 2019-08-29 10:36:17
言語 Haskell
(9.6.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 3,132 ms
コンパイル使用メモリ 157,816 KB
実行使用メモリ 7,332 KB
最終ジャッジ日時 2023-08-11 04:00:04
合計ジャッジ時間 4,338 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,200 KB
testcase_01 AC 3 ms
7,256 KB
testcase_02 AC 3 ms
7,332 KB
testcase_03 AC 3 ms
7,268 KB
testcase_04 AC 3 ms
7,240 KB
testcase_05 AC 2 ms
7,196 KB
testcase_06 AC 3 ms
7,176 KB
testcase_07 AC 3 ms
7,240 KB
testcase_08 AC 3 ms
7,200 KB
testcase_09 AC 3 ms
7,196 KB
testcase_10 AC 3 ms
7,196 KB
testcase_11 AC 2 ms
7,256 KB
testcase_12 AC 3 ms
7,176 KB
testcase_13 AC 3 ms
7,252 KB
testcase_14 AC 2 ms
7,300 KB
testcase_15 AC 3 ms
7,172 KB
testcase_16 AC 3 ms
7,312 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 #

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