Submission #1318912


Source Code Expand

p :: Int -> Int -> [Int] -> Int
p n x (y:[])
  | x + y >= 0 = n+x+y+1
  | otherwise = n
p n x (y:ys)
  | x + y >= 0 = m (n+x+y+1) (-1) ys
  | otherwise = m n (x+y) ys

m :: Int -> Int -> [Int] -> Int
m n x (y:[])
  | x + y <= 0 = n-(x+y)+1
  | otherwise = n
m n x (y:ys)
  | x + y <= 0 = p (n-(x+y)+1) 1 ys
  | otherwise = p n (x+y) ys

solve :: [Int] -> Int
solve (x:xs)
  | x < 0 = min (p (-x+1) 1 xs) (m 0 x xs)
  | x > 0 = min (p 0 x xs) (m (x+1) (-1) xs)
  | x == 0 = min (p 1 (x+1) xs) (m 1 (x-1) xs)

main = getContents >>= print . solve . map read . words . last . lines

Submission Info

Submission Time
Task C - Sequence
User sato
Language Haskell (GHC 7.10.3)
Score 300
Code Size 600 Byte
Status AC
Exec Time 620 ms
Memory 39292 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 18
Set Name Test Cases
Sample 00-00.txt, 00-01.txt, 00-02.txt
All 00-00.txt, 00-01.txt, 00-02.txt, 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt
Case Name Status Exec Time Memory
00-00.txt AC 1 ms 508 KiB
00-01.txt AC 1 ms 508 KiB
00-02.txt AC 1 ms 508 KiB
01-00.txt AC 619 ms 39292 KiB
01-01.txt AC 620 ms 39292 KiB
01-02.txt AC 601 ms 39292 KiB
01-03.txt AC 577 ms 39292 KiB
01-04.txt AC 553 ms 39292 KiB
01-05.txt AC 502 ms 39292 KiB
01-06.txt AC 598 ms 39292 KiB
01-07.txt AC 543 ms 39292 KiB
01-08.txt AC 619 ms 39292 KiB
01-09.txt AC 552 ms 39292 KiB
01-10.txt AC 460 ms 37244 KiB
01-11.txt AC 603 ms 39292 KiB
01-12.txt AC 619 ms 39292 KiB
01-13.txt AC 554 ms 39292 KiB
01-14.txt AC 619 ms 39292 KiB