結果

問題 No.179 塗り分け
ユーザー 34056915823405691582
提出日時 2017-03-24 14:01:16
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,496 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 150,272 KB
最終ジャッジ日時 2024-04-27 04:56:28
合計ジャッジ時間 476 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:1:1: error: [GHC-87110]
    Could not load module ‘Data.Map’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
1 | import Data.Map hiding (map)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

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'<n = sBCol (n',0) ++ sBRow (n'+1)
             | otherwise = []

    sBCol pos@(n',m') | m'<m =
      case lookup pos b of
        Nothing -> '.':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])
0