結果
問題 | No.199 星を描こう |
ユーザー |
|
提出日時 | 2024-04-05 01:07:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 2,465 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 56,576 KB |
最終ジャッジ日時 | 2024-10-01 00:44:09 |
合計ジャッジ時間 | 2,960 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
import sysimport mathimport bisectfrom heapq import heapify, heappop, heappushfrom collections import deque, defaultdict, Counterfrom functools import lru_cachefrom itertools import accumulate, combinations, permutations, productsys.setrecursionlimit(1000000)MOD = 10 ** 9 + 7MOD99 = 998244353input = lambda: sys.stdin.readline().strip()NI = lambda: int(input())NMI = lambda: map(int, input().split())NLI = lambda: list(NMI())SI = lambda: input()SMI = lambda: input().split()SLI = lambda: list(SMI())EI = lambda m: [NLI() for _ in range(m)]def convex(Vs):""":param Vs(sorted by x): [[x1, y1], ... [xn, yn]]:return: upper, lower"""def cross(x1, y1, x2, y2):return x1 * y2 - y1 * x2def is_ccw(x1, y1, x2, y2):return cross(x1, y1, x2, y2) >= 0N = len(Vs)upper = deque()upper.append(Vs[0])upper.append(Vs[1])for i in range(2, N):V3 = Vs[i]x3, y3 = V3while len(upper) >= 2:V2 = upper.pop()V1 = upper.pop()x2, y2 = V2x1, y1 = V1upper.append(V1)if not is_ccw(x2-x1, y2-y1, x3-x2, y3-y2):upper.append(V2)upper.append(V3)breakif len(upper) < 2:upper.append(V3)lower = deque()lower.append(Vs[-1])lower.append(Vs[-2])for i in range(N-3, -1, -1):V3 = Vs[i]x3, y3 = V3while len(lower) >= 2:V2 = lower.pop()V1 = lower.pop()x2, y2 = V2x1, y1 = V1lower.append(V1)if not is_ccw(x2-x1, y2-y1, x3-x2, y3-y2):lower.append(V2)lower.append(V3)breakif len(lower) < 2:lower.append(V3)return upper, lowerdef convex_perimeter(upper: deque, lower: deque):res = 0x, y = upper.popleft()while upper:xx, yy = upper.popleft()res += math.sqrt((x - xx) ** 2 + (y - yy) ** 2)x, y = xx, yyx, y = lower.popleft()while lower:xx, yy = lower.popleft()res += math.sqrt((x - xx) ** 2 + (y - yy) ** 2)x, y = xx, yyreturn resdef main():XY = EI(5)XY.sort()upper, lower = convex(XY)if len(upper) + len(lower) == 7:print("YES")else:print("NO")if __name__ == "__main__":main()