카테고리 없음

[codeforce][Python] #690 D. Add to Neighbour and Remove

findTheValue 2021. 12. 7. 22:15

어떻게 표현할 것인가? 결국 total값의 약수가 되어야지 가능하다.

 

import sys
input = sys.stdin.readline
 
 
for test in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    total = sum(arr)
    candidate = [num for num in range(1, total + 1) if not total % num]
    for target in candidate:
        tmp, answer = 0, 0
        for num in arr:
            tmp += num
            answer += 1
            if tmp == target:
                tmp = 0
                answer -= 1
            elif tmp > target:
                break
        else:
            print(answer)
            break