Submission #2557718
Source Code Expand
import Control.Monad (replicateM)
import Data.Array.IArray
makeGrid :: a -> (Int, Int) -> [[a]] -> Array (Int, Int) a
makeGrid e (h,w) xss = accumArray
(flip const)
e
((0,0), (h+1,w+1))
[ ((i,j), x) | (i,xs) <- zip [1..] xss
, (j,x) <- zip [1..] xs
]
adjacent :: Eq a => a -> Array (Int, Int) a -> (Int, Int) -> Bool
adjacent x grid (i,j) = grid ! (i,j) /= x
|| grid ! (i-1,j) == x
|| grid ! (i+1,j) == x
|| grid ! (i,j-1) == x
|| grid ! (i,j+1) == x
solve :: Array (Int, Int) Char -> String
solve grid = let (_, (h',w')) = bounds grid
in if all (adjacent '#' grid) [ (i,j) | i <- [1 .. h'-1]
, j <- [1 .. w'-1]
]
then "Yes"
else "No"
main :: IO ()
main = do
[h,w] <- map read . words <$> getLine
grid <- makeGrid '.' (h,w) <$> replicateM h getLine
putStrLn $ solve grid
Submission Info
Submission Time |
|
Task |
C - Grid Repainting 2 |
User |
the2830 |
Language |
Haskell (GHC 7.10.3) |
Score |
300 |
Code Size |
1186 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
1020 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name |
Status |
Exec Time |
Memory |
in01.txt |
AC |
2 ms |
892 KB |
in02.txt |
AC |
2 ms |
892 KB |
in03.txt |
AC |
2 ms |
892 KB |
in04.txt |
AC |
2 ms |
892 KB |
in05.txt |
AC |
2 ms |
892 KB |
in06.txt |
AC |
2 ms |
892 KB |
in07.txt |
AC |
2 ms |
764 KB |
in08.txt |
AC |
2 ms |
892 KB |
in09.txt |
AC |
2 ms |
892 KB |
in10.txt |
AC |
2 ms |
1020 KB |
sample_01.txt |
AC |
2 ms |
508 KB |
sample_02.txt |
AC |
2 ms |
508 KB |
sample_03.txt |
AC |
2 ms |
508 KB |