Problem p03240 (python)

Fixed submission:
import numpy as np

input_N = input().split()
N = int(input_N[0])

input_xyh = [input().split() for i in range(N)]

xyh = np.array(input_xyh)
xyh = xyh.astype(np.int64)
xyh = xyh.T
x = xyh[0]
y = xyh[1]
h = xyh[2]

# [0, 100]に座標があるのでMAXを定義する
coord_max = 101

for pos_y in range(coord_max):
    for pos_x in range(coord_max):
        # 頂上がどれくらいの高さであってほしいか
        # -1はまだよくわからないとき、0以上は確定
        # -2はダメ
        needH = -1

        for i in range(N):
            if h[i] > 0:
                tmp = h[i] + abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        if needH == -2:
            continue

        for i in range(N):
            # 高さが0の場合に矛盾してないか調べる
            if h[i] == 0:
                dist = abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH > dist:
                    needH = -2
                    break

        if needH == -2:
            continue

        # 見つけられたら答えをそのまま返す
        print(str(pos_x) + " " + str(pos_y) + " " + str(needH))

Buggy submission (verdict: Runtime Error):
import numpy as np

input_N = input().split()
N = int(input_N[0])

input_xyh = [input().split() for i in range(N)]

xyh = np.array(input_xyh)
xyh = xyh.astype(np.int64)
xyh = xyh.T
h = xyh[0]
x = xyh[1]
y = xyh[2]

# [0, 100]に座標があるのでMAXを定義する
coord_max = 100

for pos_y in range(coord_max):
    for pos_x in range(coord_max):
        # 頂上がどれくらいの高さであってほしいか
        # -1はまだよくわからないとき、0以上は確定
        # -2はダメ
        needH = -1

        for i in range(N):
            if h[i] > 0:
                tmp = h[i] + abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        if needH == -2:
            continue

        for i in range(N):
            # 高さが0の場合に矛盾してないか調べる
            if h[i] == 0:
                dist = abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH > dist:
                    needH = -2
                    break

        if needH == -2: continue

        # 見つけられたら答えをそのまま返す
        print(pos_x + " " + pos_y + " " + needH)

Buggy submission (verdict: Runtime Error):
import numpy as np

input_N = input().split()
N = int(input_N[0])

input_xyh = [input().split() for i in range(N)]

xyh = np.array(input_xyh)
xyh = xyh.astype(np.int64)
xyh = xyh.T
h = xyh[0]
x = xyh[1]
y = xyh[2]

# [0, 100]に座標があるのでMAXを定義する
coord_max = 100

for pos_y in range(coord_max):
    for pos_x in range(coord_max):
        # 頂上がどれくらいの高さであってほしいか
        # -1はまだよくわからないとき、0以上は確定
        # -2はダメ
        needH = -1

        for i in range(N):
            if h[i] > 0:
                tmp = h[i] + abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH == -1:
                    needH = tmp
                else:
                    if needH != tmp:
                        needH = -2
                        break
        if needH == -2:
            continue

        for i in range(N):
            # 高さが0の場合に矛盾してないか調べる
            if h[i] == 0:
                dist = abs(pos_y - y[i]) + abs(pos_x - x[i])
                if needH > dist:
                    needH = -2
                    break

        if needH == -2: continue

        # 見つけられたら答えをそのまま返す
        print(pos_x + " " + pos_y + " " + needH)

return 0