A40 - Triangle
提出
TLE
code: python
import itertools
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = 0
c = Counter(a)
for k, v in c.items():
if v >= 3:
ans += len(list(itertools.combinations(range(v), 3)))
print(ans)
解答
code: python
import itertools
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = 0
c = Counter(a)
for k, v in c.items():
if v >= 3:
ans += v * (v-1) * (v-2) // 6
print(ans)