結果

問題 No.154 市バス
ユーザー aimyaimy
提出日時 2017-08-31 21:50:55
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 632 bytes
コンパイル時間 3,149 ms
コンパイル使用メモリ 175,020 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-21 10:22:48
合計ジャッジ時間 5,744 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 337 ms
8,064 KB
testcase_01 AC 334 ms
8,064 KB
testcase_02 AC 334 ms
7,936 KB
testcase_03 AC 277 ms
7,936 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 RE -
testcase_07 AC 304 ms
8,064 KB
testcase_08 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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