-
Notifications
You must be signed in to change notification settings - Fork 1
/
3.2.hs
26 lines (25 loc) · 772 Bytes
/
3.2.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{-# LANGUAGE PartialTypeSignatures #-}
import Data.IORef
import qualified Data.Set as S
import Data.Array.IO
import Data.List
import Data.Maybe
import Data.Char
main = do
input <- getContents
set <- newIORef S.empty
fabric <- newArray ((0,1),(999,1000)) Nothing
mapM (\claim -> do
let
id':left:top:width:height:_ =
unfoldr (listToMaybe . reads . dropWhile (not . isDigit)) claim :: [Int]
modifyIORef set (S.insert id')
mapM (\i -> do
x <- readArray (fabric :: IOArray _ _) i
case x of
Just n -> modifyIORef set (S.delete id' . S.delete n)
Nothing -> writeArray fabric i (Just id'))
(range ((left, top), (left + width - 1, top + height - 1))))
(lines input)
s <- readIORef set
print (S.findMin s)