Problem p03240 (python)

Fixed submission:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x, y, h])


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)

# print(xyh)
ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = 0
        flag = True
        for i, (x, y, h) in enumerate(xyh):
            if i == 0:
                H = h + abs(x - c_x) + abs(y - c_y)
            if h != max(H - abs(x - c_x) - abs(y - c_y), 0):
            # if H != max(h + abs(x - c_x) + abs(y - c_y), 0):
                flag = False
        if flag:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x, y, h])


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)


ans = 0
for c_x in range(101):
    for c_y in range(101):
        H = -1
        for i, (x, y, h) in enumerate(xyh):
            if H == -1:
                H = h + abs(x - c_x) + abs(y - c_y)
            if H != h + abs(x - c_x) + abs(y - c_y):
                break
        else:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x, y, h])


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2])


ans = 0
for c_x in range(101):
    for c_y in range(101):
        H = -1
        for i, (x, y, h) in enumerate(xyh):
            if H == -1:
                H = h + abs(x - c_x) + abs(y - c_y)
            if H != h + abs(x - c_x) + abs(y - c_y):
                break
        else:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x, y, h])


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""

ans = 0
for c_x in range(101):
    for c_y in range(101):
        H = -1
        for i, (x, y, h) in enumerate(xyh):
            if H == -1 and h != 0:
                H = h + abs(x - c_x) + abs(y - c_y)
            if H != h + abs(x - c_x) + abs(y - c_y):
                break
        else:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)

Buggy submission (verdict: Runtime Error):
# encoding:utf-8
import copy
import numpy as np
import random

n = int(input())

mappings = []

for i in range(n):
    mapping = [int(i) for i in input().split()]
    mappings.append(mapping)

for cx in range(101):
    for cy in range(101):
        H = -1
        for i in range(n):
            x,y,h = mappings[i]
            if h == 0:
                pass
            else:
                if H == -1:
                    H = h+abs(x-cx)+abs(y-cy)
                elif H!=h+abs(x-cx)+abs(y-cy):
                    break

                if i == len(mappings)-1:
                    ans = (cx,cy,H)

cx,cy,H = ans
print(cx,cy,H)

Buggy submission (verdict: Runtime Error):
# encoding:utf-8
import copy
import numpy as np
import random

n = int(input())
X = []
Y = []
H = []
for i in range(n):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for x in range(101):
    for y in range(101):
        ans_h = None
        done = False
        for i in range(n):
            if done == False:
                if ans_h is None:
                    if H[i]!=0:
                        ans_h = abs(X[i]-x)+abs(Y[i]-y)+H[i]
                else:
                    if ans_h-abs(X[i]-x)-abs(Y[i]-y)==H[i]:
                        pass
                    else:
                        done = True
            else:
                break

        if done == False:
            ans = (x,y,ans_h)
x,y,h = ans
print(x,y,h)

Buggy submission (verdict: Runtime Error):
# encoding:utf-8
import copy
import numpy as np
import random

n = int(input())
X = []
Y = []
H = []
for i in range(n):
    x,y,h = map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)


for x in range(101):
    for y in range(101):
        ans_h = None
        done = False
        for i in range(n):
            if done == False:
                if ans_h is None:
                    if H[i]!=0:
                        ans_h = abs(X[i]-x)+abs(Y[i]-y)+H[i]
                else:
                    if ans_h-abs(X[i]-x)-abs(Y[i]-y)==H[i]:
                        pass
                    else:
                        done = True

        if done == False:
            ans = (x,y,ans_h)
x,y,h = ans
print(x,y,h)

Buggy submission (verdict: Runtime Error):
#encoding utf-8

n = int(input())
data = []
for i in range(n):
    x,y,h=map(int,input().split())
    data.append([x,y,h])

def calH(cx,cy,data):
    return data[2]+abs(data[0]-cx)+abs(data[1]-cy)

def conh(temH,cx,cy,data):
    return temH-abs(data[0]-cx)-abs(data[1]-cy)


for i in range(101):
    for j in range(101):
        temH = calH(i,j,data[0])
        count = 0
        for k in range(n):
            ignore_flag = 0
            if data[k][2] == 0:
                if conh(temH,i,j,data[k]) < 0:
                    ignore_flag = 1
                    count += 1

            if ignore_flag == 0:
                if calH(i,j,data[k]) != temH:
                    break
                else:
                    count += 1
            if count == n:
                answer=[i,j,calH(i,j,data[0])]

print(answer[0],answer[1],answer[2])

Buggy submission (verdict: Runtime Error):
#encoding utf-8

n = int(input())
data = []
for i in range(n):
    x,y,h=map(int,input().split())
    data.append([x,y,h])



def calH(cx,cy,data):
    return data[2]+abs(data[0]-cx)+abs(data[1]-cy)

for i in range(101):
    for j in range(101):
        temH = calH(i,j,data[0])
        for k in range(n):
            if calH(i,j,data[k]) != temH:
                break
            else:
                if k == n-1:
                    answer=[i,j,calH(i,j,data[0])]

print(answer[0],answer[1],answer[2])