結果

問題 No.179 塗り分け
ユーザー aimyaimy
提出日時 2017-05-20 09:10:46
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 834 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 143,232 KB
最終ジャッジ日時 2023-11-30 06:20:16
合計ジャッジ時間 1,155 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

Main.hs:6:1: error:
    Could not load module ‘Data.IntMap’
    It is a member of the hidden package ‘containers-0.6.7’.
    You can run ‘:set -package containers’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
6 | import Data.IntMap ((!))
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:7:1: error:
    Could not load module ‘Data.IntMap’
    It is a member of the hidden package ‘containers-0.6.7’.
    You can run ‘:set -package containers’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
7 | import qualified Data.IntMap as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Data.Char
import Data.Bool
import Data.List
import Data.Maybe
import Control.Monad
import Data.IntMap ((!))
import qualified Data.IntMap as M

main = do
 [h,w] <- map read . words <$> getLine
 cs <- filter isPrint <$> getContents
 let is = map fst $ filter ((=='#').snd) (zip [1000*h' + w' | h'<-[0..h-1], w'<-[0..w-1]] cs)
 putStrLn $ bool "NO" "YES" (dpaint h w (M.fromDistinctAscList (zip is (repeat False))))

dpaint h w icm
 | M.null icm = False
 | otherwise = or $ map (\d -> isJust (foldl' (paint d) (return icm) idx)) ds
 where
  idx = M.keys icm
  ds = [i | h'<-[0..h-1], w'<-[negate (w-1) .. w-1], let i = 1000*h'+w', i>0]

paint _ Nothing _ = Nothing
paint d (Just icm) i
 | icm ! i = return icm
 | (not . M.member (i+d)) icm = Nothing
 | otherwise =  return (M.unionWith (||) (M.fromList [(i,True),(i+d,True)]) icm)
0