import Data.Map hiding (map) import Data.Maybe import Control.Monad import Prelude hiding (lookup,null) type Board = Map (Int,Int) (Maybe Bool) test1 = concat ["######...\n", "#.####.#.\n", "######...\n"] test2 = concat ["..............##................\n", "..........##########............\n", "......##################........\n", "..##########################....\n", "##....##################....##..\n", "######....##########....######..\n", "##########....##....##########..\n", "##....########..##############..\n", "######....####..##############..\n", "##############..##############..\n", "##############..##############..\n", "##############..##############..\n", "..############..############....\n", "......########..########........\n", "..........####..####............\n", "..............##................\n"] main = do [m,n] <- map read . words <$> getLine :: IO [Int] c <- getContents putStrLn $ if isSeparatable (m,n) (genBoard c) then "YES" else "NO" genBoard :: String -> Board genBoard = gBRow 0 . lines where gBRow _ [] = empty gBRow n (line:ls) = gBCol (gBRow (n+1) ls) (n,0) line gBCol b _ [] = b gBCol b (n,m) (square:ss) = if square=='#' then insert (n,m) Nothing b' else b' where b' = gBCol b (n,m+1) ss showBoard :: (Int,Int) -> Board -> String showBoard (n,m) b = sBRow 0 where sBRow n' | n' '.':rest Just Nothing -> '#':rest Just (Just True) -> 'X':rest Just (Just False) -> 'O':rest | otherwise = "\n" where rest = sBCol (n',m'+1) colorBoard :: (Int,Int) -> Board -> Maybe Board colorBoard (m,n) b = cB b $ keys b where cB b' [] = Just b' cB b' ((m',n'):ps) = case b'!(m',n') of Nothing -> case lookup (m'+m,n'+n) b' of Just Nothing -> cB (insert (m'+m,n'+n) (Just False) $ insert (m',n') (Just True) b') ps _ -> Nothing Just False -> cB b' ps isSeparatable :: (Int,Int) -> Board -> Bool isSeparatable (m,n) b = (&&) (not $ null b) $ or $ isJust <$> (colorBoard <$> [(x,y)|x<-[0..m],y<-[-n..n],x/=0||y/=0] <*> [b]) --isSeparatable (m,n) b = (||) (null b) $ or $ isJust <$> (colorBoard <$> (tail [(x,y)|x<-[0..m],y<-[-n..n]] ++ [(x,y)|x<-[0..m],y<-[-1..(-n)]]) <*> [b])