Submission #55870820


Source Code Expand

Copy
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Array
import qualified Data.Heap as H
import Data.Array.IO
main :: IO ()
main = do
hwy@(h:_) <- bsGetLnInts
ass <- replicateM h bsGetLnInts
abc363e hwy ass
bsGetLnInts :: IO [Int]
bsGetLnInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
abc363e :: [Int] -> [[Int]] -> IO ()
abc363e [h,w,y] ass =
do
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

import Data.Array
import qualified Data.Heap as H
import Data.Array.IO

main :: IO ()
main = do
  hwy@(h:_) <- bsGetLnInts
  ass <- replicateM h bsGetLnInts
  abc363e hwy ass

bsGetLnInts :: IO [Int]
bsGetLnInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

abc363e :: [Int] -> [[Int]] -> IO ()
abc363e [h,w,y] ass =
  do
    seaside <- newArray bnds False
    forM_ seaside0ps (\p -> writeArray seaside p True)
    undersea <- newArray bnds False
    loop 1 seaside undersea (h * w) seasideQ0
  where
    bnds = ((1,1),(h,w))
    a = listArray bnds $ concat ass
    seaside0ps = [(i,1) | i <- [1..h]] ++ [(i,w) | w > 1, i <- [1..h]] ++
                 [(1,j) | j <- [2 .. pred w]] ++ [(h,j) | h > 1, j <- [2 .. pred w]]
    seasideQ0 = H.fromList [H.Entry ap p | p <- seaside0ps, let ap = a ! p, ap <= y ]

    loop :: Int -- 今から検討する時刻=水面高さ
         -> IOUArray (Int,Int) Bool -- 海に面した陸地フラグ
         -> IOUArray (Int,Int) Bool -- 水没済みフラグ
         -> Int -- 陸地マスの個数
         -> H.Heap (H.Entry Int (Int,Int)) -- 海に面した陸地の高さ順キュー
         -> IO ()
    loop t seaside underwater count q =
      case H.uncons q of
        Nothing       -> replicateM_ (y - pred t) (print count)
        Just (H.Entry aij ij@(i,j), q1)
          | t < aij   -> replicateM_ (aij -    t) (print count) >> loop aij seaside underwater count q
          | otherwise -> do
              writeArray underwater ij True
              q2 <- foldM (\ss ne -> do
                b1 <- readArray seaside    ne
                b2 <- readArray underwater ne
                let ane = a ! ne
                if b1 || b2 || ane > y then return ss else do
                  writeArray seaside ne True
                  return $ H.insert (H.Entry ane ne) ss
                ) q1 $ [(pred i, j) | i > 1] ++ [(succ i, j) | i < h] ++ [(i, pred j) | j > 1] ++ [(i, succ j) | j < w]
              loop t seaside underwater (pred count) q2

{-
IOUArray Bool で管理するようにして、間に合うようにはなったが、handで2つほどWAになってしまう。あれぇ?
タイムも割とぎりぎり。

キューをなるべく短く保つため、そもそもYより大きい場所はseasideに登録しないようにする。
groundはnotでチェックしているので、逆にする。

WAは多分あれだ。端を多重登録するのと同じで、WやHが1なんだ。くっそwww
-}

Submission Info

Submission Time
Task E - Sinking Land
User joetheshootingst
Language Haskell (GHC 9.4.5)
Score 450
Code Size 2651 Byte
Status AC
Exec Time 1728 ms
Memory 228692 KB

Compile Error

app/Main.hs:20:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘abc363e’:
        Patterns of type ‘[Int]’, ‘[[Int]]’ not matched:
            [] _
            [_] _
            [_, _] _
            (_:_:_:_:_) _
   |
20 | abc363e [h,w,y] ass =
   | ^^^^^^^^^^^^^^^^^^^^^...

app/Main.hs:31:65: warning: [-Wname-shadowing]
    This binding for ‘ap’ shadows the existing binding
      imported from ‘Control.Monad’ at app/Main.hs:1:1-20
      (and originally defined in ‘GHC.Base’)
   |
31 |     seasideQ0 = H.fromList [H.Entry ap p | p <- seaside0ps, let ap = a ! p, ap <= y ]
   |                                                                 ^^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 6932 KB
example_01.txt AC 1 ms 6940 KB
hand_00.txt AC 458 ms 215324 KB
hand_01.txt AC 458 ms 215420 KB
hand_02.txt AC 446 ms 134860 KB
hand_03.txt AC 21 ms 11416 KB
hand_04.txt AC 21 ms 11392 KB
hand_05.txt AC 21 ms 10884 KB
hand_06.txt AC 1728 ms 221520 KB
hand_07.txt AC 386 ms 149344 KB
hand_08.txt AC 123 ms 55632 KB
hand_09.txt AC 1336 ms 146900 KB
hand_10.txt AC 376 ms 149340 KB
hand_11.txt AC 1 ms 6832 KB
hand_12.txt AC 103 ms 54428 KB
hand_13.txt AC 1 ms 6892 KB
random_00.txt AC 1657 ms 175212 KB
random_01.txt AC 1667 ms 174384 KB
random_02.txt AC 1697 ms 176136 KB
random_03.txt AC 1697 ms 173392 KB
random_04.txt AC 1657 ms 174008 KB
random_05.txt AC 1567 ms 169284 KB
random_06.txt AC 1566 ms 152880 KB
random_07.txt AC 1536 ms 168064 KB
random_08.txt AC 1536 ms 166008 KB
random_09.txt AC 1556 ms 148388 KB
random_10.txt AC 1386 ms 138596 KB
random_11.txt AC 1436 ms 139548 KB
random_12.txt AC 1376 ms 137548 KB
random_13.txt AC 1376 ms 138604 KB
random_14.txt AC 1396 ms 138296 KB
random_15.txt AC 1136 ms 138280 KB
random_16.txt AC 1146 ms 139228 KB
random_17.txt AC 1146 ms 140480 KB
random_18.txt AC 1136 ms 137324 KB
random_19.txt AC 1166 ms 139536 KB
random_20.txt AC 1535 ms 120776 KB
random_21.txt AC 1505 ms 122088 KB
random_22.txt AC 1515 ms 121148 KB
random_23.txt AC 1515 ms 122816 KB
random_24.txt AC 1615 ms 122928 KB
random_25.txt AC 1418 ms 228592 KB
random_26.txt AC 1428 ms 228672 KB
random_27.txt AC 1408 ms 228612 KB
random_28.txt AC 1348 ms 227488 KB
random_29.txt AC 1378 ms 228692 KB


2025-04-26 (Sat)
08:47:52 +00:00