Submission #38235250
Source Code Expand
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array
main = do
n <- readLn
as <- map read . words <$> getLine
ss <- replicateM n getLine
let arr = abc286ep n as ss
let aa = listArray (1,n) as
q <- readLn
replicateM_ q $ do
[u,v] <- map read . words <$> getLine
let ans = abc286em arr aa u v
putStrLn ans
type DA = Array (Int,Int) (Int,Int) -- 距離の表
abc286ep :: Int -- N
-> [Int] -- Ai
-> [String] -- Si
-> DA -- 距離の表
abc286ep n as ss = runSTArray action
where
action :: ST s (STArray s (Int, Int) (Int, Int))
action = 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
-> String -- 答え
abc286em arr aa i j
| k == maxBound = "Impossible"
| otherwise = unwords [show k, show $ aa ! j - a]
where
(k,a) = arr ! (i,j)
Submission Info
| Submission Time | |
|---|---|
| Task | E - Souvenir |
| User | joetheshootingst |
| Language | Haskell (GHC 8.8.3) |
| Score | 0 |
| Code Size | 1731 Byte |
| Status | TLE |
| Exec Time | 3309 ms |
| Memory | 30976 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 | 0 / 500 | ||||||
| Status |
|
|
| 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 | 5 ms | 3972 KiB |
| example_01.txt | AC | 2 ms | 3832 KiB |
| hand_00.txt | TLE | 3308 ms | 19904 KiB |
| hand_01.txt | TLE | 3309 ms | 30976 KiB |
| hand_02.txt | TLE | 3309 ms | 21996 KiB |
| hand_03.txt | TLE | 3309 ms | 20808 KiB |
| hand_04.txt | AC | 9 ms | 3836 KiB |
| random_00.txt | TLE | 3308 ms | 20904 KiB |
| random_01.txt | TLE | 3308 ms | 19780 KiB |
| random_02.txt | TLE | 3308 ms | 21948 KiB |
| random_03.txt | TLE | 3308 ms | 21928 KiB |
| random_04.txt | TLE | 3308 ms | 20868 KiB |
| random_05.txt | TLE | 3308 ms | 20904 KiB |
| random_06.txt | TLE | 3308 ms | 19776 KiB |
| random_07.txt | TLE | 3308 ms | 19776 KiB |
| random_08.txt | TLE | 3308 ms | 20928 KiB |
| random_09.txt | TLE | 3308 ms | 20972 KiB |
| random_10.txt | TLE | 3308 ms | 20924 KiB |
| random_11.txt | TLE | 3308 ms | 20780 KiB |
| random_12.txt | TLE | 3308 ms | 20740 KiB |
| random_13.txt | TLE | 3308 ms | 20908 KiB |
| random_14.txt | TLE | 3309 ms | 23988 KiB |
| random_15.txt | TLE | 3308 ms | 20924 KiB |
| random_16.txt | TLE | 3308 ms | 20900 KiB |
| random_17.txt | TLE | 3308 ms | 20736 KiB |
| random_18.txt | TLE | 3308 ms | 22000 KiB |
| random_19.txt | TLE | 3308 ms | 21952 KiB |
| random_20.txt | TLE | 3308 ms | 21996 KiB |
| random_21.txt | TLE | 3309 ms | 27068 KiB |
| random_22.txt | TLE | 3308 ms | 21928 KiB |
| random_23.txt | TLE | 3308 ms | 20956 KiB |
| random_24.txt | TLE | 3308 ms | 19476 KiB |
| random_25.txt | TLE | 3308 ms | 20712 KiB |
| random_26.txt | TLE | 3308 ms | 19916 KiB |
| random_27.txt | TLE | 3308 ms | 20928 KiB |
| random_28.txt | TLE | 3308 ms | 19908 KiB |
| random_29.txt | TLE | 3309 ms | 22920 KiB |
| random_30.txt | TLE | 3309 ms | 22976 KiB |
| random_31.txt | TLE | 3308 ms | 20920 KiB |
| random_32.txt | TLE | 3308 ms | 20924 KiB |
| random_33.txt | TLE | 3308 ms | 19720 KiB |
| random_34.txt | TLE | 3308 ms | 21944 KiB |
| random_35.txt | TLE | 3309 ms | 23940 KiB |
| random_36.txt | TLE | 3309 ms | 24000 KiB |
| random_37.txt | TLE | 3308 ms | 19944 KiB |
| random_38.txt | TLE | 3308 ms | 18880 KiB |