Submission #1484523


Source Code Expand

import Control.Monad
import Data.Maybe

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- getInts
  bs <- getInts
  let as'= decide as
      bs' = reverse $ decide (reverse bs)
      ms = zipWith (min) as bs
      xs = solve as' bs' ms
  print $ fromMaybe 0 (solve' <$> xs)
  

getInts :: IO [Int]
getInts = map read . words <$> getLine

decide :: [Int] -> [Int]
decide ns = go (zip ns (0 : init ns))
  where
    go [] = []
    go ((c, n):xs)
      | c == n = -1 : go xs
      | otherwise = c : go xs

solve :: [Int] -> [Int] -> [Int] -> Maybe [Int]
solve as bs mins = go as bs mins
  where
    go [] _ _ = Just []
    go (x:xs) (y:ys) (m:ms)
      | x == y && y == (-1) = fmap (m :) (go xs ys ms)
      | x == y = fmap (-1 :) (go xs ys ms)
      | x == -1 = fmap (-1 :) (go xs ys ms)
      | y == -1 = fmap (-1 :) (go xs ys ms)
      | otherwise = Nothing

solve' :: [Int] -> Int
solve' ns = go ns
  where
    go [] = 1
    go (n:ns)
      | n == -1 = go ns
      | otherwise = (n * go ns) `mod` 1000000007

Submission Info

Submission Time
Task C - Two Alpinists
User nmjiri
Language Haskell (GHC 7.10.3)
Score 0
Code Size 1058 Byte
Status WA
Exec Time 1346 ms
Memory 140028 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 18
WA × 3
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt
Case Name Status Exec Time Memory
0_000.txt AC 2 ms 508 KB
0_001.txt AC 2 ms 508 KB
0_002.txt AC 2 ms 636 KB
0_003.txt AC 2 ms 508 KB
1_004.txt AC 2 ms 508 KB
1_005.txt AC 2 ms 508 KB
1_006.txt WA 2 ms 508 KB
1_007.txt AC 2 ms 508 KB
1_008.txt AC 1346 ms 140028 KB
1_009.txt AC 1172 ms 106876 KB
1_010.txt AC 1232 ms 113532 KB
1_011.txt AC 1282 ms 123260 KB
1_012.txt AC 784 ms 111996 KB
1_013.txt AC 1276 ms 122748 KB
1_014.txt AC 791 ms 113020 KB
1_015.txt AC 1287 ms 124924 KB
1_016.txt AC 892 ms 119548 KB
1_017.txt AC 1213 ms 112380 KB
1_018.txt WA 1201 ms 109052 KB
1_019.txt AC 1085 ms 101756 KB
1_020.txt WA 1047 ms 92540 KB