Problem p02805 (python)

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if abs(d)<10**(-16):
        return (0,0),float('inf')
    x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
    y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
    r = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
    return (x, y), r

N = I()
x,y = Line(N,2)

if N==2:
    print((math.sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))/2)
    exit()

ans = float('inf')
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            c,r = get_circle_center_and_radius(x[i],y[i],x[j],y[j],x[k],y[k])
            if r<ans:
                check = False
                for h in range(N):
                    if h in [i,j,k]:
                        continue
                    if math.sqrt((x[h]-c[0])**2 + (y[h]-c[1])**2)>r:
                        check = True
                if not check:
                    ans = r

for i in range(N-1):
    for j in range(i+1,N):
        c = ((x[i]+x[j])/2, (y[i]+y[j])/2)
        r = (math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2))/2
        flag = False
        for k in range(N):
            if k in [i,j]:
                continue
            else:
                if math.sqrt((x[k]-c[0])**2 + (y[k]-c[1])**2)>r:
                    flag = True
                    break
        if not flag:
            if r<ans:
                ans = r

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from decimal import Decimal

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if abs(d)<10**(-16):
        return (0,0),float('inf')
    x = Decimal(((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d)(20)
    y = Decimal(((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d)(20)
    r = Decimal(math.sqrt((x - x1) ** 2 + (y - y1) ** 2))(20)
    return (x, y), r

N = I()
x,y = Line(N,2)

if N==2:
    print((math.sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))/2)
    exit()

ans = float('inf')
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            c,r = get_circle_center_and_radius(x[i],y[i],x[j],y[j],x[k],y[k])
            if r<ans:
                check = False
                for h in range(N):
                    if h in [i,j,k]:
                        continue
                    if Decimal(math.sqrt((x[h]-c[0])**2 + (y[h]-c[1])**2))(20)>r:
                        check = True
                if not check:
                    ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from decimal import Decimal

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if abs(d)<10**(-16):
        return (0,0),float('inf')
    x = Decimal(((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d)(20)
    y = Decimal(((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d)(20)
    r = Decimal(math.sqrt((x - x1) ** 2 + (y - y1) ** 2))(20)
    return (x, y), r

N = I()
x,y = Line(N,2)

if N==2:
    print((math.sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))/2)
    exit()

ans = float('inf')
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            c,r = get_circle_center_and_radius(x[i],y[i],x[j],y[j],x[k],y[k])
            if r<ans:
                check = False
                for h in range(N):
                    if h in [i,j,k]:
                        continue
                    if math.sqrt((x[h]-c[0])**2 + (y[h]-c[1])**2)>r:
                        check = True
                if not check:
                    ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from decimal import Decimal

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if abs(d)<10**(-16):
        return (0,0),float('inf')
    x = Decimal((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d)(20)
    y = Decimal(((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d)(20)
    r = Decimal(math.sqrt((x - x1) ** 2 + (y - y1) ** 2))(20)
    return (x, y), r

N = I()
x,y = Line(N,2)

if N==2:
    print((math.sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))/2)
    exit()

ans = float('inf')
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            c,r = get_circle_center_and_radius(x[i],y[i],x[j],y[j],x[k],y[k])
            if r<ans:
                check = False
                for h in range(N):
                    if h in [i,j,k]:
                        continue
                    if math.sqrt((x[h]-c[0])**2 + (y[h]-c[1])**2)>r:
                        check = True
                if not check:
                    ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if abs(d)<10**(-16):
        return (0,0),float('inf')
    x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
    y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
    r = Decimal(math.sqrt((x - x1) ** 2 + (y - y1) ** 2))
    return (x, y), r

N = I()
x,y = Line(N,2)

if N==2:
    print((math.sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))/2)
    exit()

ans = float('inf')
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            c,r = get_circle_center_and_radius(x[i],y[i],x[j],y[j],x[k],y[k])
            if r<ans:
                check = False
                for h in range(N):
                    if h in [i,j,k]:
                        continue
                    if math.sqrt((x[h]-c[0])**2 + (y[h]-c[1])**2)>r:
                        check = True
                if not check:
                    ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

import numpy as np
from numpy import linalg as LA

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if d==0:
        return (0,0),float('inf')
    x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
    y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
    r = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
    return (x, y), r

N = I()
x,y = Line(N,2)

if N==2:
    print((math.sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))/2)
    exit()

ans = float('inf')
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            '''
            u = np.array([x[j]-x[i],y[j]-y[i]])
            v = np.array([x[k]-x[i],y[j]-y[i]])
            X = np.inner(u, v)
            n = LA.norm(u) * LA.norm(v)
            if n==0:
                continue
            C = X / n
            a = np.rad2deg(np.arccos(np.clip(C, -1.0, 1.0)))
            if a==0.0:
                continue
            '''
            c,r = get_circle_center_and_radius(x[i],y[i],x[j],y[j],x[k],y[k])
            if r<ans:
                check = False
                for h in range(N):
                    if h in [i,j,k]:
                        continue
                    if math.sqrt((x[h]-c[0])**2 + (y[h]-c[1])**2)>r:
                        check = True
                if not check:
                    ans = r
print(ans)