LoginSignup
0
0

More than 1 year has passed since last update.

ABC224 C - Triangle? を解いた

Posted at

abc224c1.png
abc224c2.png
abc224c3.png
abc224c4.png

選んだ3点が一直線上になる組み合わせを
数えて全体の組み合わせから引けばいい。

abc224c.py
def solv():
    N = int(input())
    lis = []
    for _ in range(N):
        x,y = map(int,input().split())
        lis.append([x,y])

    from itertools import combinations
    cnt = 0
    for a,b,c in combinations(range(N),3):
        if (lis[a][1]-lis[b][1])*(lis[a][0]-lis[c][0]) == (lis[a][1]-lis[c][1])*(lis[a][0]-lis[b][0]):
            cnt += 1
    print( (N*(N-1)*(N-2))//6 - cnt)

solv()

計算量は 10^7 オーダーになるので、
def でまとめて、pypy で提出すればいい

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0