목차

나누기

ps
링크acmicpc.net/…
출처BOJ
문제 번호21757
문제명나누기
레벨골드 3
분류

DP

시간복잡도O(n)
인풋사이즈n<100,000
사용한 언어Python
제출기록42028KB / 112ms
최고기록112ms
해결날짜2022/02/13

풀이

코드

"""Solution code for "BOJ 21757. 나누기".

- Problem link: https://www.acmicpc.net/problem/21757
- Solution link: http://www.teferi.net/ps/problems/boj/21757
"""


def main():
    N = int(input())  # pylint: disable=unused-variable
    A = [int(x) for x in input().split()]

    q, r = divmod(sum(A), 4)
    if r != 0:
        print('0')
        return
    q1, q2, q3 = q, q * 2, q * 3
    q1_count = q2_count = q3_count = 0
    s = 0
    for a_i in A[:-1]:
        s += a_i
        if s == q3:
            q3_count += q2_count
        if s == q2:
            q2_count += q1_count
        if s == q1:
            q1_count += 1

    print(q3_count)


if __name__ == '__main__':
    main()