Skip to content

Instantly share code, notes, and snippets.

@uchidama
Created July 2, 2021 16:37
Show Gist options
  • Save uchidama/758c568f2e9bdeb383df7d9a505e8290 to your computer and use it in GitHub Desktop.
Save uchidama/758c568f2e9bdeb383df7d9a505e8290 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 181 [ C - Collinearity ] https://atcoder.jp/contests/abc181/tasks/abc181_c
'''
[問題]
https://atcoder.jp/contests/abc181/tasks/abc181_c
[解説]
https://atcoder.jp/contests/abc181/editorial/258
[結果]
PyPy3(7.3.0) AC 65ms
Python(3.8.2) AC 110ms
'''
import sys
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
N = int(input())
P = [tuple(map(int, input().split())) for i in range(N)]
for i in range(N):
for j in range(i): # N -> i でif文回避
for k in range(j): # N -> j でif文回避
# j, k のループを工夫してるので、このif文いらない
#if i == j or i == k or j == k:
# continue
# x1 = 0, y1 = 0 にして、x2,y2,x3,y3を平行移動
x1, y1 = P[i]
x2, y2 = P[j]
x3, y3 = P[k]
x2 -= x1
y2 -= y1
x3 -= x1
y3 -= y1
x1 = 0
y1 = 0
# 傾きが一致するか見る。y2/x2 == y3/x3
# zero divide対策でx2*x3を両辺にかける
# y2*x3 == y3*x2
if y2*x3 == y3*x2:
print("Yes")
exit()
print("No")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment