• + 0 comments

    haskell

    import Control.Monad (forM_)
    
    full r g b y "" = r == g && y == b
    full r g b y ('R':cs) = r <= g && full (r+1) g b y cs
    full r g b y ('G':cs) = r >= g && full r (g+1) b y cs
    full r g b y ('B':cs) = y >= b && full r g (b+1) y cs
    full r g b y ('Y':cs) = y <= b && full r g b (y+1) cs
    
    main = do
      ns <- getLine
      forM_ [1..(read ns)] $ \  _ -> do
        seq <- getLine
        print $ full 0 0 0 0 seq