結果

問題 No.154 市バス
ユーザー ducktailducktail
提出日時 2018-09-13 15:15:27
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 563 bytes
コンパイル時間 11,299 ms
コンパイル使用メモリ 170,112 KB
実行使用メモリ 58,404 KB
最終ジャッジ日時 2023-09-13 19:52:53
合計ジャッジ時間 4,371 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
58,404 KB
testcase_01 AC 202 ms
58,252 KB
testcase_02 AC 212 ms
58,360 KB
testcase_03 AC 202 ms
57,344 KB
testcase_04 AC 202 ms
58,356 KB
testcase_05 WA -
testcase_06 AC 3 ms
6,916 KB
testcase_07 AC 212 ms
58,404 KB
testcase_08 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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" $ last bs == 'R' && f (0, 0) bs
  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