Problem p03428 (python)

Fixed submission:
import math

N = int(input())
xys = [tuple(map(int, input().split())) for _ in range(N)]

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

outside = [min(range(N), key = lambda i: xys[i])]

go_back_to_while = False
while outside:
    i = outside[-1]
    x1, y1 = xys[i]
    for j in range(N):
        if j in outside:
            continue
        x2, y2 = xys[j]
        sign = 0
        for k, (x3, y3) in enumerate(xys):
            if k == i or k == j:
                continue
            tmp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
            if tmp == 0:
                if x1 < x3 < x2 or x1 > x3 > x2 or y1 < y3 < y2 or y1 > y3 > y2:
                    if k in outside:
                        outside.remove(k)
                        outside.append(j)
                        go_back_to_while = True
                        break
                elif x1 < x2 < x3 or x1 > x2 > x3 or y1 < y2 < y3 or y1 > y2 > y3:
                    break
                else:
                    outside.pop() #remove i
                    go_back_to_while = True
                    break
            elif tmp > 0:
                if sign == 0:
                    sign = +1
                elif sign == -1:
                    break
                else:
                    continue
            else:
                if sign == 0:
                    sign = -1
                elif sign == +1:
                    break
                else:
                    continue
        else:
            outside.append(j)
            break
        if go_back_to_while:
            go_back_to_while = False
            break
    else: #when not found appropriate j
        break #get out of while True


ans = [0.0] * N

for i in range(-1, len(outside) - 1):
    x1, y1 = xys[outside[i-1]]
    x2, y2 = xys[outside[i]]
    x3, y3 = xys[outside[i+1]]
    v1x, v1y = x2 - x1, y2 - y1
    v2x, v2y = x3 - x2, y3 - y2
    dot = v1x * v2x + v1y * v2y
    len1 = (v1x ** 2 + v1y ** 2)
    len2 = (v2x ** 2 + v2y ** 2)
    ans[outside[i]] = math.acos( max(-1.0, min(1.0, dot / math.sqrt(len1 * len2))) ) / (2 * math.pi)

for a in ans:
    print('{:.20f}'.format(a))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
xys = [tuple(map(int, input().split())) for _ in range(N)]

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

outside = []
for i in range(N):
    x1, y1 = xys[i]
    for j in range(i+1, N):
        x2, y2 = xys[j]
        sign = 0
        for x3, y3 in xys:
            tmp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
            if tmp == 0:
                continue
            elif tmp > 0:
                if sign == 0:
                    sign = +1
                elif sign == -1:
                    continue_flg = True
                    break
                else:
                    continue
            else:
                if sign == 0:
                    sign = -1
                elif sign == +1:
                    continue_flg = True
                    break
                else:
                    continue
        else:
            outside.append(i)
            outside.append(j)
            continue_flg = False
            break
    if continue_flg == False:
        break

go_back_to_while = False
while True:
    i = outside[-1]
    x1, y1 = xys[i]
    for j in range(N):
        if j in outside:
            continue
        x2, y2 = xys[j]
        sign = 0
        for k, (x3, y3) in enumerate(xys):
            if k == i or k == j:
                continue
            tmp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
            if tmp == 0:
                if x1 < x3 < x2 or x1 > x3 > x2 or y1 < y3 < y2 or y1 > y3 > y2:
                    if k in outside:
                        outside.remove(k)
                        outside.append(j)
                        go_back_to_while = True
                        break
                elif x1 < x2 < x3 or x1 > x2 > x3 or y1 < y2 < y3 or y1 > y2 > y3:
                    break
                else:
                    outside.pop() #remove i
                    go_back_to_while = True
                    break
            elif tmp > 0:
                if sign == 0:
                    sign = +1
                elif sign == -1:
                    break
                else:
                    continue
            else:
                if sign == 0:
                    sign = -1
                elif sign == +1:
                    break
                else:
                    continue
        else:
            outside.append(j)
            break
        if go_back_to_while:
            go_back_to_while = False
            break
    else: #when not found appropriate j
        break #get out of while True


ans = [0.0] * N

for i in range(-1, len(outside) - 1):
    x1, y1 = xys[outside[i-1]]
    x2, y2 = xys[outside[i]]
    x3, y3 = xys[outside[i+1]]
    v1x, v1y = x2 - x1, y2 - y1
    v2x, v2y = x3 - x2, y3 - y2
    dot = v1x * v2x + v1y * v2y
    len1 = (v1x ** 2 + v1y ** 2)
    len2 = (v2x ** 2 + v2y ** 2)
    ans[outside[i]] = math.acos( max(-1.0, min(1.0, dot / math.sqrt(len1 * len2))) ) / (2 * math.pi)

for a in ans:
    print('{:.20f}'.format(a))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
xys = [tuple(map(int, input().split())) for _ in range(N)]

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

outside = []
for i in range(N):
    x1, y1 = xys[i]
    for j in range(i+1, N):
        x2, y2 = xys[j]
        sign = 0
        for x3, y3 in xys:
            tmp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
            if tmp == 0:
                continue
            elif tmp > 0:
                if sign == 0:
                    sign = +1
                elif sign == -1:
                    continue_flg = True
                    break
                else:
                    continue
            else:
                if sign == 0:
                    sign = -1
                elif sign == +1:
                    continue_flg = True
                    break
                else:
                    continue
        else:
            outside.append(i)
            outside.append(j)
            continue_flg = False
            break
    if continue_flg == False:
        break

while True:
    i = outside[-1]
    x1, y1 = xys[i]
    for j in range(N):
        if j in outside:
            continue
        x2, y2 = xys[j]
        sign = 0
        for x3, y3 in xys:
            tmp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
            if tmp == 0:
                continue
            elif tmp > 0:
                if sign == 0:
                    sign = +1
                elif sign == -1:
                    continue_flg = True
                    break
                else:
                    continue
            else:
                if sign == 0:
                    sign = -1
                elif sign == +1:
                    continue_flg = True
                    break
                else:
                    continue
        else:
            outside.append(j)
            continue_flg = False
            break
    else: #when not found appropriate j
        break #get out of while True

ans = [0.0] * N

for i in range(-1, len(outside) - 1):
    x1, y1 = xys[outside[i-1]]
    x2, y2 = xys[outside[i]]
    x3, y3 = xys[outside[i+1]]
    v1x, v1y = x2 - x1, y2 - y1
    v2x, v2y = x3 - x2, y3 - y2
    dot = v1x * v2x + v1y * v2y
    len1 = (v1x ** 2 + v1y ** 2) ** 0.5
    len2 = (v2x ** 2 + v2y ** 2) ** 0.5
    ans[outside[i]] = math.acos( dot / (len1 * len2) ) / (2 * math.pi)

for a in ans:
    print('{:.7f}'.format(a))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
xys = [tuple(map(int, input().split())) for _ in range(N)]

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

outside = []
for i in range(N):
    x1, y1 = xys[i]
    for j in range(i+1, N):
        x2, y2 = xys[j]
        sign = 0
        for x3, y3 in xys:
            tmp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
            if tmp == 0:
                continue
            elif tmp > 0:
                if sign == 0:
                    sign = +1
                elif sign == -1:
                    continue_flg = True
                    break
                else:
                    continue
            else:
                if sign == 0:
                    sign = -1
                elif sign == +1:
                    continue_flg = True
                    break
                else:
                    continue
        else:
            outside.append(i)
            outside.append(j)
            continue_flg = False
            break
    if continue_flg == False:
        break

while True:
    i = outside[-1]
    x1, y1 = xys[i]
    for j in range(N):
        if i == j:
            continue
        if outside[-2] == j:
            continue
        if outside[0] == j:
            continue
        x2, y2 = xys[j]
        sign = 0
        for x3, y3 in xys:
            tmp = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
            if tmp == 0:
                continue
            elif tmp > 0:
                if sign == 0:
                    sign = +1
                elif sign == -1:
                    continue_flg = True
                    break
                else:
                    continue
            else:
                if sign == 0:
                    sign = -1
                elif sign == +1:
                    continue_flg = True
                    break
                else:
                    continue
        else:
            outside.append(j)
            continue_flg = False
            break
    else: #when not found appropriate j
        break #get out of while True

ans = [0.0] * N

for i in range(-1, len(outside) - 1):
    x1, y1 = xys[outside[i-1]]
    x2, y2 = xys[outside[i]]
    x3, y3 = xys[outside[i+1]]
    v1x, v1y = x2 - x1, y2 - y1
    v2x, v2y = x3 - x2, y3 - y2
    dot = v1x * v2x + v1y * v2y
    len1 = (v1x ** 2 + v1y ** 2) ** 0.5
    len2 = (v2x ** 2 + v2y ** 2) ** 0.5
    ans[outside[i]] = math.acos( dot / (len1 * len2) ) / math.tau # = 2pi

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