結果

問題 No.154 市バス
ユーザー ducktailducktail
提出日時 2018-09-13 16:00:15
言語 Haskell
(9.8.2)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 164,068 KB
実行使用メモリ 58,444 KB
最終ジャッジ日時 2023-09-13 19:53:33
合計ジャッジ時間 3,004 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
58,400 KB
testcase_01 AC 222 ms
58,408 KB
testcase_02 AC 212 ms
58,324 KB
testcase_03 AC 182 ms
55,340 KB
testcase_04 AC 212 ms
57,272 KB
testcase_05 AC 2 ms
7,024 KB
testcase_06 AC 3 ms
6,904 KB
testcase_07 AC 223 ms
58,444 KB
testcase_08 AC 3 ms
6,928 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 Control.Monad
import Data.Bool (bool)

main :: IO ()
main = do
  n <- readLn
  map solve <$> replicateM n getLine >>= mapM_ putStrLn

solve :: String -> String
solve bs = bool "impossible" "possible" $ f (0, 0) bs && last bs == 'R' && last (filter (/= 'R') bs) == 'G'
  where
    f (_, g) [] = g == 0
    f (w, g) (b:bs)
      | b == 'R' = if g > 0
                     then f (w, g - 1) bs
                     else False
      | b == 'G' = if w > 0
                     then f (w - 1, g + 1) bs
                     else False
      | otherwise = f (w + 1, g) bs
0