Submission #1961470


Source Code Expand

N = int(input())
A = list(map(int, input().split()))

def func(A, plus):
  total = A[0]
  ans = 0
  if plus:
    if A[0] <= 0:
      ans = abs(A[0])+1
      total = 1
  else:
    if A[0] >= 0:
      ans += abs(A[0])+1
      total = -1
  for a in A[1:]:
    t = total + a
    if total * t < 0:
      total = t
      continue
    ans += abs(t)+1
    total = -1 if total > 0 else 1
  return ans

print(min(func(A, True), func(A, False)))

Submission Info

Submission Time
Task C - Sequence
User espressivosubito
Language Python (3.4.3)
Score 300
Code Size 457 Byte
Status AC
Exec Time 86 ms
Memory 14468 KB

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 18 ms 3064 KB
00-01.txt AC 17 ms 3064 KB
00-02.txt AC 17 ms 3064 KB
01-00.txt AC 83 ms 14332 KB
01-01.txt AC 86 ms 14468 KB
01-02.txt AC 81 ms 13876 KB
01-03.txt AC 79 ms 13280 KB
01-04.txt AC 78 ms 12764 KB
01-05.txt AC 72 ms 11884 KB
01-06.txt AC 81 ms 13672 KB
01-07.txt AC 77 ms 12552 KB
01-08.txt AC 83 ms 14464 KB
01-09.txt AC 76 ms 12756 KB
01-10.txt AC 65 ms 11068 KB
01-11.txt AC 83 ms 13788 KB
01-12.txt AC 83 ms 14468 KB
01-13.txt AC 78 ms 13140 KB
01-14.txt AC 84 ms 14332 KB