This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
"""
COCI 2016/2017 Round 2
Given an array of integers [a1, a2, ... an]
perform an operation that combines a1 and a2
or combines an and an-1
Find minimum operations such that array is
a palindrome
"""
N = int(input())
arr = list(map(int, input().split()))
k, i, j = 0, 0, N - 1
while i < j:
if arr[i] == arr[j]:
i += 1
j -= 1
elif arr[i] < arr[j]:
arr[i + 1] += arr[i]
i += 1
k += 1
else:
arr[j - 1] += arr[j]
j -= 1
k += 1
print(k)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |