結果
| 問題 |
No.3154 convex polygon judge
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-10 17:58:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 649 ms / 2,000 ms |
| コード長 | 1,499 bytes |
| コンパイル時間 | 436 ms |
| コンパイル使用メモリ | 82,576 KB |
| 実行使用メモリ | 100,868 KB |
| 最終ジャッジ日時 | 2025-05-10 17:58:48 |
| 合計ジャッジ時間 | 6,793 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
def arg_sort(points:list[tuple[int]]):
"""
0°closed
"""
n = len(points)
p = [(0,0)]*n
pidx = -1
nidx = n
for x,y in points:
if x == 0 and y == 0:
pass
elif y < 0 or (x > 0 and y == 0):
pidx += 1
p[pidx] = (x,y)
else:
nidx -= 1
p[nidx] = (x,y)
que = []
if pidx != -1: que.append((0,pidx))
if nidx != n: que.append((nidx,n-1))
while que:
i,j = que.pop()
left,right = i,j
pivot = (i+j)//2
px,py = p[pivot]
while True:
while px*p[i][1] - py*p[i][0] < 0: i += 1
while p[j][0]*py - p[j][1]*px < 0: j -= 1
if i >= j: break
p[i],p[j] = p[j],p[i]
i += 1
j -= 1
if left < i-1: que.append((left, i-1))
if right > j+1: que.append((j+1, right))
return p
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (b[0] - o[0]) * (a[1] - o[1])
n = int(input())
p = []
sx = 0
sy = 0
for i in range(n):
x,y = map(int, input().split())
p.append((n*x, n*y))
sx += x
sy += y
# 重心が原点になるように移動する
p = [(x - sx, y - sy) for x, y in p]
# 偏角ソート
p = arg_sort(p)
for i in range(n):
a, b, c = p[i-2], p[i-1], p[i]
# 必要十分条件は
# 有向角CBAが180°未満 <=> 外積が正
if cross(b, c, a) <= 0:
print("No")
exit()
print("Yes")