Skip to content

Instantly share code, notes, and snippets.

@uchidama
Last active July 9, 2021 14:01
Show Gist options
  • Select an option

  • Save uchidama/625454e86fd5c8bd2af411a02d5b5d54 to your computer and use it in GitHub Desktop.

Select an option

Save uchidama/625454e86fd5c8bd2af411a02d5b5d54 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 175 [ B - Making Triangle ] https://atcoder.jp/contests/abc175/tasks/abc175_b
'''
[問題]
https://atcoder.jp/contests/abc175/tasks/abc175_b
[解説]
https://atcoder.jp/contests/abc175/editorial/50
[参考]
http://physics.thick.jp/Mathematics_A/Section5/5-3.html
三角形には、2つの辺の長さを足し合わせると残りの1つの辺の長さより長くなる。
'''
import sys
import itertools
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
N = int(input())
A = list(map(int, input().split()))
ans = 0
for v in itertools.combinations(range(N), 3):
L = [A[v[0]],A[v[1]],A[v[2]]]
L.sort()
# 三角形には、2つの辺の長さを足し合わせると残りの1つの辺の長さより長くなる。
if L[0] != L[1] and L[1] != L[2] and L[0] + L[1] > L[2]:
ans += 1
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment