結果

問題 No.859 路線A、路線B、路線C
ユーザー dsplitdsplit
提出日時 2019-08-11 12:29:35
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 2,611 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 163,916 KB
実行使用メモリ 6,876 KB
最終ジャッジ日時 2023-10-11 13:53:15
合計ジャッジ時間 1,842 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,796 KB
testcase_01 AC 2 ms
6,748 KB
testcase_02 AC 2 ms
6,768 KB
testcase_03 AC 2 ms
6,832 KB
testcase_04 AC 2 ms
6,804 KB
testcase_05 AC 3 ms
6,876 KB
testcase_06 AC 2 ms
6,868 KB
testcase_07 AC 3 ms
6,828 KB
testcase_08 AC 3 ms
6,832 KB
testcase_09 AC 2 ms
6,820 KB
testcase_10 AC 2 ms
6,816 KB
testcase_11 AC 3 ms
6,804 KB
testcase_12 AC 2 ms
6,788 KB
testcase_13 AC 2 ms
6,844 KB
testcase_14 AC 2 ms
6,832 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

main :: IO ()
main = do
   xs <- words <$> getContents
   putStrLn $ show $ solve xs

solve :: [String] -> Integer
solve [x, y, z, startRosen, start, endRosen, end] = f (read x, read y, read z, startRosen, read start, endRosen, read end)
    where
        f :: (Integer, Integer, Integer, String, Integer, String, Integer) -> Integer
        f (a, b, c, s1, st, s2, ed)
            | s1 == s2  = g (s1, a, b, c, st, ed)
            | otherwise = h (s1, s2, a, b, c, st, ed)

g :: (String, Integer, Integer, Integer, Integer, Integer) -> Integer
g (s, a, b, c, start, end) = minimum xs
    where
        xs = case s of
            "A" -> [abs (end - start), if start < end then (start - 1) + 1 + (b - 1) + 1 + (a - end) else (a - start) + 1 + (b - 1) + 1 + (end - 1), if start < end then (start - 1) + 1 + (c - 1) + 1 + (a - end) else (a - start) + 1 + (c - 1) + 1 + (end - 1)]
            "B" -> [abs (end - start), if start < end then (start - 1) + 1 + (a - 1) + 1 + (b - end) else (b - start) + 1 + (a - 1) + 1 + (end - 1), if start < end then (start - 1) + 1 + (c - 1) + 1 + (b - end) else (b - start) + 1 + (c - 1) + 1 + (end - 1)]
            "C" -> [abs (end - start), if start < end then (start - 1) + 1 + (a - 1) + 1 + (c - end) else (c - start) + 1 + (b - 1) + 1 + (end - 1), if start < end then (start - 1) + 1 + (b - 1) + 1 + (c - end) else (c - start) + 1 + (a - 1) + 1 + (end - 1)]
h :: (String, String, Integer, Integer, Integer, Integer, Integer) -> Integer
h (s1, s2, a, b, c, start, end) = minimum xs
    where
        xs = case (s1, s2) of
            ("A", "B") -> [(a - start) + 1 + (c - 1) + 1 + (end - 1), (a - start) + 1 + (b - end), (start - 1) + 1 + (end - 1), (start - 1) + 1 + (c - 1) + 1 + (b - end)]
            ("A", "C") -> [(a - start) + 1 + (b - 1) + 1 + (end - 1), (a - start) + 1 + (c - end), (start - 1) + 1 + (end - 1), (start - 1) + 1 + (b - 1) + 1 + (c - end)]
            ("B", "C") -> [(b - start) + 1 + (a - 1) + 1 + (end - 1), (b - start) + 1 + (c - end), (start - 1) + 1 + (end - 1), (start - 1) + 1 + (a - 1) + 1 + (c - end)]
            ("B", "A") -> [(b - start) + 1 + (c - 1) + 1 + (end - 1), (b - start) + 1 + (a - end), (start - 1) + 1 + (end - 1), (start - 1) + 1 + (c - 1) + 1 + (a - end)]
            ("C", "A") -> [(c - start) + 1 + (b - 1) + 1 + (end - 1), (c - start) + 1 + (a - end), (start - 1) + 1 + (end - 1), (start - 1) + 1 + (b - 1) + 1 + (a - end)]
            ("C", "B") -> [(c - start) + 1 + (a - 1) + 1 + (end - 1), (c - start) + 1 + (b - end), (start - 1) + 1 + (end - 1), (start - 1) + 1 + (a - 1) + 1 + (b - end)]
0