Problem: In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.   The pyramid had _center coordinates_ (C_X, C_Y) and _height_ H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).  Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:    * C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.    * Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."   This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Submission attempts (in order):
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]


height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        candidate = 0
        for x, y, h in xyh:
            if h == 0: continue
            dx = abs(x - cx)
            dy = abs(y - cy)
            candidate = dx + dy + h 
            break

        found = True
        for x, y, h in xyh:
            # if h == 0: continue
            # if h + abs(x - cx) + abs(y - cy) != candidate:
            if candidate - abs(x - cx) - abs(y - cy) - h >= 0:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)


N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]


candidate = lambda xyh, cx, cy: abs(xyh[0] - cx) + abs(xyh[1] - cy) + xyh[2]

height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        found = True
        candidates = [candidate(xyhi, cx, cy) for xyhi in xyh]

        found = True
        height = None
        for candidate in candidates:
            if candidate < 0: continue
            if height is None:
                height = candidate
                continue
            if candidate != height:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)


N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]


height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        candidate = 0
        for x, y, h in xyh:
            if h == 0: continue
            dx = abs(x - cx)
            dy = abs(y - cy)
            candidate = dx + dy + h 
            break

        found = True
        for x, y, h in xyh:
            # if h == 0: continue
            # if h + abs(x - cx) + abs(y - cy) != candidate:
            if candidate - abs(x - cx) - abs(y - cy) - h > 0:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)


N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]


height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        candidate = 0
        for x, y, h in xyh:
            if h == 0: continue
            dx = abs(x - cx)
            dy = abs(y - cy)
            candidate = dx + dy + h 
            break

        found = True
        for x, y, h in xyh:
            # if h == 0: continue
            # if h + abs(x - cx) + abs(y - cy) != candidate:
            if candidate - abs(x - cx) - abs(y - cy) - h <= 0:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)


N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]


height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        height = abs(xyh[0][0] - cx) + abs(xyh[0][1] - cy) + xyh[0][2]
        foo = [(abs(x - cx) + abs(y - cy) + h == height or (abs(x - cx) + abs(y - cy) + h == 0) for x, y, h in xyh]
        found = all(foo)
        if found: break
    if found: break
print(cx, cy, height)


N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]


height = None
found = False
for cx in range(0, 101):
    for cy in range(0, 101):
        candidate = 0
        for x, y, h in xyh:
            if h == 0: continue
            dx = abs(x - cx)
            dy = abs(y - cy)
            candidate = dx + dy + h 
            break

        found = True
        for x, y, h in xyh:
            _h = max(candidate - abs(x - cx) - abs(y - cy), 0)
            if h != _h:
                found = False
                break
        
        if found is True: break
    if found is True: break
height = candidate if candidate is not None else 0

print(cx, cy, height)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted