Problem p03428 (python)

Fixed submission:
import cmath
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def det(a: complex, b: complex):
    # 外積
    return a.real * b.imag - a.imag * b.real


def graham_scan(points):
    """
    凸包
    :param list of complex|np.ndarray points:
    :rtype: list of complex
    """
    if len(points) <= 2:
        return list(points)
    points = np.sort_complex(points)
    # Graham Scan
    sz = 0
    #: :type: list of (complex|None)
    ret = [None] * (N * 2)
    for p in points:
        while sz > 1 and det(ret[sz - 1] - ret[sz - 2], p - ret[sz - 1]) <= 0:
            sz -= 1
        ret[sz] = p
        sz += 1
    floor = sz
    for p in reversed(points[:-1]):
        while sz > floor and det(ret[sz - 1] - ret[sz - 2], p - ret[sz - 1]) <= 0:
            sz -= 1
        ret[sz] = p
        sz += 1
    ret = ret[:sz - 1]
    return ret


N = int(sys.stdin.buffer.readline())
X, Y = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))
TAU = math.pi * 2

points = [complex(x, y) for x, y in zip(X, Y)]
pos = {p: i for i, p in enumerate(points)}

# 凸包
points = graham_scan(points)
points = np.array(points, dtype=complex)
assert len(points) >= 2

ans = [0.0] * N

if len(points) == 2:
    ans[pos[points[0]]] = 0.5
    ans[pos[points[1]]] = 0.5
    print(*ans, sep='\n')
    exit()

# 中心からの角度でソート
center = points.mean()
idx = np.angle(points - center).argsort()
points = points[idx]

for i in range(len(points)):
    pr = points[(i + 1) % len(points)]
    p = points[i]
    pl = points[(i - 1) % len(points)]

    # 凸包の内側から、頂点の両隣の辺に垂線をおろしたときの角度
    # pi - 角度
    ans[pos[p]] += (math.pi - (cmath.phase(pl - p) - cmath.phase(pr - p)) % TAU) / TAU

print(*ans, sep='\n')

# from matplotlib import pyplot as plt
#
# points -= center
# theta = [cmath.phase(p) for p in points]
# r = np.array([abs(p) for p in points])
#
# fig = plt.figure()
# ax = fig.add_subplot(111, projection='polar')
# ax.set_ylim([-max(r) * 1.2, max(r) * 1.2])
# ax.scatter(theta, r)
# plt.show()
# print(r)

Buggy submission (verdict: Runtime Error):
import cmath
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def det(a: complex, b: complex):
    # 外積
    return a.real * b.imag - a.imag * b.real


def graham_scan(points):
    """
    凸包
    :param list of complex|np.ndarray points:
    :rtype: list of complex
    """
    if len(points) <= 2:
        return list(points)
    points = np.sort_complex(points)
    # Graham Scan
    sz = 0
    #: :type: list of (complex|None)
    ret = [None] * N
    for p in points:
        while sz > 1 and det(ret[sz - 1] - ret[sz - 2], p - ret[sz - 1]) <= 0:
            sz -= 1
        ret[sz] = p
        sz += 1
    floor = sz
    for p in reversed(points[:-1]):
        while sz > floor and det(ret[sz - 1] - ret[sz - 2], p - ret[sz - 1]) <= 0:
            sz -= 1
        ret[sz] = p
        sz += 1
    ret = ret[:sz - 1]
    return ret


N = int(sys.stdin.buffer.readline())
X, Y = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))
TAU = math.pi * 2

if N == 2:
    print(0.5)
    print(0.5)
    exit()

points = [complex(x, y) for x, y in zip(X, Y)]
pos = {p: i for i, p in enumerate(points)}

# 凸包
points = graham_scan(points)
points = np.array(points, dtype=complex)

# 中心からの角度でソート
center = points.mean()
idx = np.angle(points - center).argsort()
points = points[idx]

ans = [0.0] * N
for i in range(len(points)):
    pr = points[(i + 1) % len(points)]
    p = points[i]
    pl = points[(i - 1) % len(points)]

    # 凸包の内側から、頂点の両隣の辺に垂線をおろしたときの角度
    # pi - 角度
    ans[pos[p]] += (math.pi - (cmath.phase(pl - p) - cmath.phase(pr - p)) % TAU) / TAU

if ans:
    print(*ans, sep='\n')

# from matplotlib import pyplot as plt
#
# points -= center
# theta = [cmath.phase(p) for p in points]
# r = [abs(p) for p in points]
#
# fig = plt.figure()
# ax = fig.add_subplot(111, projection='polar')
# ax.scatter(theta, r, s=max(r))
# plt.show()