This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
def split_array_helper(nums, index, sum1, sum2, arr1, arr2):
size = len(nums)
if index == size:
return sum1 == sum2
arr1.append(nums[index])
if split_array_helper(nums, index + 1, sum1 + nums[index], sum2, arr1, arr2):
return True
arr1.pop()
arr2.append(nums[index])
if split_array_helper(nums, index + 1, sum1, sum2 + nums[index], arr1, arr2):
return True
arr2.pop()
return False
def split_array(nums, arr1, arr2):
sum1, sum2 = 0, 0
return split_array_helper(nums, 0, sum1, sum2, arr1, arr2)
n = int(input())
arr = list(map(int, input().split()))
arr2, arr3 = [], []
res = []
total_sum = sum(arr)
ruined = False
for i in range(1, total_sum + 1):
ruined = False
size = len(arr)
if size > n:
arr.pop()
arr.append(i)
for k in range(n + 1):
darr = arr[:]
del darr[k]
if not split_array(darr, arr2, arr3):
ruined = True
break
arr2.clear()
arr3.clear()
if not ruined:
res.append(i)
print(len(res))
if res:
print(" ".join(map(str, res)))
# | 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... |