6 条题解

题解与来源题共享。已有题解默认通过;新增或编辑后需由来源域管理员审核。待审核、驳回题解仅作者和审核管理员可见。来源域:system

  • 0
    @ 2026-5-11 16:36:00
    import os
    import sys
    n = int(input())
    a = map(int, input().split())
    s = [0]
    for i in a:
        s.append(s[-1] + i)
    t = s[-1] // 3
    if t * 3 != s[-1]:
        print(0)
    else:
        c0 = 0
        c1 = 0
        ind = []
        for i0 in range(1, len(s)):
            i = s[i0]
            if i == t:
                c0 += 1
                ind.append(i0)
            elif i == s[-1] - t:
                c1 += 1
        if t != 0:
            print(c0 * c1)
        else:
            r = 0
            for i in range(len(ind)):
                for j in range(i + 1, len(ind)):
                    if ind[j] == n:
                        continue
                    r += 1
                
            print(r)
    

    信息

    ID
    513
    时间
    1000ms
    内存
    256MiB
    难度
    普及−
    标签
    递交数
    1501
    已通过
    250
    上传者