結果
問題 |
No.859 路線A、路線B、路線C
|
ユーザー |
![]() |
提出日時 | 2019-08-11 11:38:52 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,134 bytes |
コンパイル時間 | 9,240 ms |
コンパイル使用メモリ | 177,272 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-09-13 11:37:35 |
合計ジャッジ時間 | 10,155 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 1 |
コンパイルメッセージ
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
ソースコード
import Control.Applicative main :: IO () main = do xs <- words <$> getContents putStrLn $ show $ solve xs solve :: [String] -> Int solve [x, y, z, startRosen, start, endRosen, end] = f (read x, read y, read z, startRosen, read start, endRosen, read end) where f :: (Int, Int, Int, String, Int, String, Int) -> Int 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, Int, Int, Int, Int, Int) -> Int g (s, a, b, c, start, end) = minimum xs where xs = case s of "A" -> [abs (end - start), (start - 1) + 1 + (b - 1) + 1 + (a - end), (start - 1) + 1 + (c - 1) + 1 + (a - end)] "B" -> [abs (end - start), (start - 1) + 1 + (a - 1) + 1 + (b - end), (start - 1) + 1 + (c - 1) + 1 + (b - end)] "C" -> [abs (end - start), (start - 1) + 1 + (a - 1) + 1 + (c - end), (start - 1) + 1 + (b - 1) + 1 + (c - end)] h :: (String, String, Int, Int, Int, Int, Int) -> Int 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)]