CSES - HIIT Open 2019 - Results
Submission details
Task:Grid Paths
Sender:Omochiikaeri~!
Submission time:2019-05-25 13:06:42 +0300
Language:Haskell
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.13 sdetails

Compiler report

input/code.hs:1:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature: main :: IO ()

input/code.hs:11:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature: modulo :: Integer

input/code.hs:13:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      next :: [Integer] -> (Int, [Integer]) -> [Integer]

input/code.hs:16:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature: pt :: [[Integer]]

input/code.hs:16:14: warning: [-Wtype-defaults]
    * Defaulting the following constraints to type `Integer'
        (Num a0) arising from a use of `pt_calc' at input/code.hs:16:14-20
        (Num a0) arising from a use of `+' at input/code.hs:14:18-20
        (Num a0)
          arising from the literal `1000000007' at input/code.hs:11:10-19
        (Show a0) arising from a use of `show' at input/code.hs:9:16-36
        (Integral a0) arising from a use of `mod' at input/code.hs:9:23-36...

Code

main = do
    n_ <- getLine
    let n = read n_
    
    grid_ <- sequence $ take n $ repeat getLine
    let grid = map (map read . words) grid_
    
    let res = foldl next (tail $ scanl (+) 0 $ head grid) (zip [1..] $ tail grid) !! (n-1)
    putStrLn $ show $ mod res modulo

modulo = 1000000007

next prev (row, l) =
    tail $ scanl (+) 0 $ zipWith (+) prev (zipWith (*) (muls row) l)

pt = iterate pt_calc [1]

pt_calc prev =
    1 : zipWith (+) prev (tail prev) ++ [1]

muls row =
    map (\x -> (pt !! (row+x)) !! row) [0..]

Test details

Test 1

Verdict: ACCEPTED

input
100
606755118 96655535 664126532 4...

correct output
530182530

user output
530182530