Submission #38235338


Source Code Expand

import Control.Monad
import Data.Array.IO
import Data.Array

main = do
  n <- readLn
  as <- map read . words <$> getLine
  ss <- replicateM n getLine
  arr <- abc286ep n as ss
  let aa = listArray (1,n) as
  q <- readLn
  replicateM_ q $ do
    [u,v] <- map read . words <$> getLine
    ans <- abc286em arr aa u v
    putStrLn ans

type DA = IOArray (Int,Int) (Int,Int) -- 距離の表

abc286ep :: Int       -- N
         -> [Int]     -- Ai
         -> [String]  -- Si
         -> IO DA        -- 距離の表
abc286ep n as ss = do
      arr <- newListArray ((1,1),(n,n)) $
        [ if sij == 'N' then (maxBound, 0) else (1, - ai)
        | (i,si,ai) <- zip3 [1..] ss as
        , (j,sij)   <- zip  [1..] si
        ]
      forM_ [1..n] (\k ->
        forM_ [1..n] (\i -> do
          dik <- readArray arr (i,k)
          when (dik < (maxBound, 0)) (
            forM_ [1..n] (\j -> do
              dkj <- readArray arr (k,j)
              when (dkj < (maxBound, 0)) $ do
                let dikj = add dik dkj
                dij <- readArray arr (i,j)
                when (dij > dikj) $ writeArray arr (i,j) dikj
              )
            )
          )
        )
      return arr

add (a,b) (c,d) = (a+c,b+d)

-- クエリ対応
abc286em :: DA            -- 距離の表
         -> Array Int Int -- Ai
         -> Int           -- Ui
         -> Int           -- Vi
         -> IO String        -- 答え
abc286em arr aa i j = do
  (k,a) <- readArray arr (i,j)
  return $ if k == maxBound then "Impossible" else unwords [show k, show $ aa ! j - a]

Submission Info

Submission Time
Task E - Souvenir
User joetheshootingst
Language Haskell (GHC 8.8.3)
Score 500
Code Size 1613 Byte
Status AC
Exec Time 772 ms
Memory 18588 KiB

Compile Error

Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
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, 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, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt
Case Name Status Exec Time Memory
example_00.txt AC 6 ms 3764 KiB
example_01.txt AC 2 ms 3940 KiB
hand_00.txt AC 650 ms 13936 KiB
hand_01.txt AC 432 ms 18588 KiB
hand_02.txt AC 258 ms 13940 KiB
hand_03.txt AC 653 ms 13828 KiB
hand_04.txt AC 5 ms 3836 KiB
random_00.txt AC 323 ms 14592 KiB
random_01.txt AC 328 ms 15200 KiB
random_02.txt AC 334 ms 15504 KiB
random_03.txt AC 334 ms 15512 KiB
random_04.txt AC 313 ms 14464 KiB
random_05.txt AC 635 ms 13820 KiB
random_06.txt AC 636 ms 13940 KiB
random_07.txt AC 630 ms 13912 KiB
random_08.txt AC 248 ms 13888 KiB
random_09.txt AC 259 ms 13896 KiB
random_10.txt AC 259 ms 13968 KiB
random_11.txt AC 329 ms 13824 KiB
random_12.txt AC 256 ms 13860 KiB
random_13.txt AC 253 ms 14016 KiB
random_14.txt AC 604 ms 18032 KiB
random_15.txt AC 619 ms 15988 KiB
random_16.txt AC 252 ms 13768 KiB
random_17.txt AC 246 ms 14056 KiB
random_18.txt AC 656 ms 16064 KiB
random_19.txt AC 654 ms 15956 KiB
random_20.txt AC 653 ms 15880 KiB
random_21.txt AC 506 ms 16900 KiB
random_22.txt AC 676 ms 15872 KiB
random_23.txt AC 487 ms 13952 KiB
random_24.txt AC 544 ms 13936 KiB
random_25.txt AC 553 ms 14416 KiB
random_26.txt AC 608 ms 14920 KiB
random_27.txt AC 664 ms 14964 KiB
random_28.txt AC 388 ms 13832 KiB
random_29.txt AC 545 ms 15876 KiB
random_30.txt AC 640 ms 16008 KiB
random_31.txt AC 245 ms 13912 KiB
random_32.txt AC 251 ms 13528 KiB
random_33.txt AC 264 ms 13828 KiB
random_34.txt AC 404 ms 15876 KiB
random_35.txt AC 627 ms 18152 KiB
random_36.txt AC 675 ms 17008 KiB
random_37.txt AC 772 ms 14052 KiB
random_38.txt AC 668 ms 14060 KiB