服了...建议py党还是别做这道题了
查看原帖
服了...建议py党还是别做这道题了
355685
LIQYSA楼主2023/5/26 12:06

用了题解的做法,各种细节无论怎么改都是TLE30分。时限卡的是不是有点......我是蚌埠住了,摆烂好了

n = int(input())
a = [0] * 5001
for i in range(n):
    a[int(input())] += 1
s = 0
for i in range(2, 5001):
    if a[i] >= 2:
        y = a[i] * (a[i] - 1) // 2
        z = 0
        if i % 2:
            z = a[i // 2] * a[i // 2 + 1]
        else:
            z = a[i // 2] * (a[i // 2] - 1) // 2
        for j in range(1, i // 2):
            z += a[j] * a[i - j]
        s += y * z
print(s % 1000000007)
2023/5/26 12:06
加载中...