結果

問題 No.154 市バス
ユーザー gigurururugigurururu
提出日時 2015-02-18 00:39:03
言語 Haskell
(9.6.2)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 164,648 KB
実行使用メモリ 11,172 KB
最終ジャッジ日時 2023-08-03 09:14:42
合計ジャッジ時間 3,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
11,168 KB
testcase_01 AC 82 ms
11,132 KB
testcase_02 AC 82 ms
11,160 KB
testcase_03 AC 72 ms
11,172 KB
testcase_04 AC 82 ms
11,088 KB
testcase_05 AC 2 ms
6,684 KB
testcase_06 AC 2 ms
6,728 KB
testcase_07 AC 72 ms
11,164 KB
testcase_08 AC 2 ms
6,820 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.List
import Debug.Trace

check :: String -> String
check str = if check_sub 0 0 0 str then "possible" else "impossible"
  where
    check_sub r g b "" = r == 0 && g == 0
    check_sub r g w (x:xs)
      | x == 'R' = check_sub (r+1) g w xs
      | x == 'G' = if r > 0
          then check_sub (r-1) (g+1) w xs
          else False
      | x == 'W' && g > 0 = check_sub r (g-1) (w+1) xs
      | x == 'W' && w > 0 = check_sub r g (w+1) xs
      | otherwise         = False

main = do
  mapM_ putStrLn =<< map (check.reverse) <$> drop 1 <$> lines <$> getContents
0