結果

問題 No.154 市バス
ユーザー aimy
提出日時 2017-08-31 21:50:55
言語 Haskell
(9.10.1)
結果
WA  
実行時間 -
コード長 632 bytes
コンパイル時間 2,806 ms
コンパイル使用メモリ 174,976 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-10-13 09:10:24
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other AC * 6 WA * 1 RE * 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

ソースコード

diff #

import Data.Bool
import Data.List

main = getLine >> interact (unlines . map (bool "impossible" "possible" . citybus) . lines)

citybus s = and [num, restR, restG, pairGR]
  where
    num = let [g,r,w] = map (pred.length) (group (sort ("WGR"++s))) in g == r && w >= g
    restR = (=="R") $ last $ filter (\(b:_) -> b=='R') $ delete [] $ tails s
    restG = (notElem 'W') $ last $ filter (\(b:_) -> b=='G') $ delete [] $ tails s
    pairGR = foldr pairGRgo (Just 0) s == Just 0

pairGRgo _ Nothing = Nothing
pairGRgo 'R' (Just n) = Just (n + 1)
pairGRgo 'G' (Just n)
  | n == 0 = Nothing
  | otherwise = Just (n - 1)
pairGRgo _ m = m
0