結果

問題 No.149 碁石の移動
ユーザー iwotiwot
提出日時 2020-06-07 19:45:35
言語 Haskell
(9.8.2)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 2,961 ms
コンパイル使用メモリ 159,804 KB
実行使用メモリ 25,448 KB
最終ジャッジ日時 2023-08-25 13:07:11
合計ジャッジ時間 4,454 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,420 KB
testcase_01 AC 3 ms
8,052 KB
testcase_02 AC 2 ms
6,868 KB
testcase_03 AC 2 ms
6,868 KB
testcase_04 AC 2 ms
6,780 KB
testcase_05 AC 12 ms
13,576 KB
testcase_06 AC 13 ms
14,552 KB
testcase_07 AC 2 ms
6,836 KB
testcase_08 AC 2 ms
6,816 KB
testcase_09 AC 3 ms
7,560 KB
testcase_10 AC 5 ms
10,184 KB
testcase_11 AC 12 ms
13,972 KB
testcase_12 AC 5 ms
10,204 KB
testcase_13 AC 6 ms
10,720 KB
testcase_14 AC 7 ms
11,020 KB
testcase_15 AC 32 ms
20,876 KB
testcase_16 AC 53 ms
25,448 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 #

main :: IO ()
main = do
    [aw,ab] <- map read . words <$> getLine
    [bw,bb] <- map read . words <$> getLine
    [c,d] <- map read . words <$> getLine
    print $ solve aw ab bw bb c d

solve :: Int -> Int -> Int -> Int -> Int -> Int -> Int
solve aw ab bw bb c d = white (fst $ fst b)
    where a = fukuroA ((White aw),(Black ab)) ((White bw),(Black bb)) c
          b = uncurry fukuroB a d

white :: White -> Int
white (White n) = n

data White = White Int deriving (Show, Eq)
data Black = Black Int deriving (Show, Eq)

fukuroA
    :: (White, Black)
    -> (White, Black)
    -> Int
    -> ((White, Black), (White, Black))
fukuroA (w1,b1) (w2,b2) 0 = ((w1,b1), (w2,b2))
fukuroA (White 0, Black 0) (w2, b2) t = ((White 0, Black 0), (w2, b2))
fukuroA (White w1, Black 0) (White w2, b2) t =
    fukuroA (White (w1 - 1), Black 0) (White (w2+1), b2) (t-1)
fukuroA (w1, Black b1) (w2, Black b2) t =
    fukuroA (w1, Black (b1-1)) (w2, Black (b2 + 1)) (t - 1)

fukuroB
    :: (White, Black)
    -> (White, Black)
    -> Int
    -> ((White, Black), (White, Black))
fukuroB (w1, b1) (w2, b2) 0 = ((w1, b1), (w2, b2))
fukuroB (w1, b1) (White 0, Black 0) t = ((w1, b1), (White 0, Black 0))
fukuroB (w1, Black b1) (White 0, Black b2) t =
    fukuroB (w1, Black (b1+1)) (White 0, Black (b2-1)) (t-1)
fukuroB (White w1, b1) (White w2, b2) t =
    fukuroB (White (w1+1), b1) (White (w2-1), b2) (t - 1)
0