Problem p03112 (python)

Fixed submission:
#%%
import bisect

#%%
a,b,q = map(int, input().split())
INF = 10**18
shrines = [-INF] + [int(input()) for _ in range(a)] + [INF]
temples = [-INF] + [int(input()) for _ in range(b)] + [INF]

for _ in range(q):

    start = int(input())

    # スタート位置より右にある神社のうち、もっともスタート位置に近いもの
    shrine_east = shrines[bisect.bisect_right(shrines, start)]
    # スタート位置より右にある寺のうち、もっともスタート位置に近いもの
    temple_east = temples[bisect.bisect_right(temples, start)]

    # スタート位置より左にある神社のうち、もっともスタート位置に近いもの
    shrine_west = shrines[bisect.bisect_right(shrines, start) - 1]
    # スタート位置より左にある寺のうち、もっともスタート位置に近いもの
    temple_west = temples[bisect.bisect_right(temples, start) - 1]

    ans = INF

    for shrine in [shrine_east, shrine_west]:
        for temple in [temple_east,temple_west]:
            cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)
            ans = min(ans,cur)

    print(ans)

Buggy submission (verdict: Runtime Error):
#%%
import bisect

#%%
a,b,q = map(int, input().split())
INF = 10**18
shrines = [-INF] + [int(input() for _ in range(a))] + [INF]
temples = [-INF] + [int(input() for _ in range(b))] + [INF]

for _ in range(q):

    start = int(input())

    # スタート位置より右にある神社のうち、もっともスタート位置に近いもの
    shrine_east = shrines[bisect.bisect_right(shrines, start)]
    # スタート位置より右にある寺のうち、もっともスタート位置に近いもの
    temple_east = temples[bisect.bisect_right(temples, start)]

    # スタート位置より左にある神社のうち、もっともスタート位置に近いもの
    shrine_west = shrines[bisect.bisect_right(shrines, start) - 1]
    # スタート位置より左にある寺のうち、もっともスタート位置に近いもの
    temple_west = temples[bisect.bisect_right(temples, start) - 1]

    ans = INF

    for shrine in [shrine_east, shrine_west]:
        for temple in [temple_east,temple_west]:
            cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)
            ans = min(ans,cur)

    print(ans)



#%%
arr = [4,8,12,16,20]

#%%
bisect.bisect_left(arr,12)

#%%
bisect.bisect_right(arr,12)

#%%

Buggy submission (verdict: Runtime Error):
import bisect

#%%
a,b,q = map(int, input().split())
INF = 10**18
shrines = [-INF] + [int(input() for _ in range(a))] + [INF]
temples = [-INF] + [int(input() for _ in range(b))] + [INF]

for _ in range(q):

    start = int(input())

    # スタート位置より右にある神社のうち、もっともスタート位置に近いもの
    shrine_east = shrines[bisect.bisect_right(shrines, start)]
    # スタート位置より右にある寺のうち、もっともスタート位置に近いもの
    temple_east = temples[bisect.bisect_right(temples, start)]

    # スタート位置より左にある神社のうち、もっともスタート位置に近いもの
    shrine_west = shirines[bisect.bisect_right(shrines, start) - 1]
    # スタート位置より左にある寺のうち、もっともスタート位置に近いもの
    temple_west = temples[bisect.bisect_right(temples, start) - 1]

    ans = INF

    for shrine in [shrine_east, shrine_west]:
        for temple in [temple_east,temple_west]:
            cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)
            ans = min(ans,cur)

    print(ans)

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

s,t,q = list(map(int, input().split()))
shrines = []
temples = []
questions = []
answers = []
dist = np.empty((s,t),dtype='int64')

for _ in range(s):
    shrines.append(int(input()))
shrines = np.array(shrines)

for _ in range(t):
    temples.append(int(input()))
temples = np.array(temples)

for _ in range(q):
    questions.append(int(input()))

for i, shrine in enumerate(shrines):
    dist[i]= [abs(shrine - temple) for temple in temples]

#%%
print(shrines,temples,dist)

#%%
for start in questions:
    min_shrine_start = float('inf')
    min_temple_start = float('inf')

    for i, st_s in enumerate(shrines - start):
        abs_st_s = abs(st_s)

        if abs_st_s < min_shrine_start:
            abs_st_s += np.min(dist[i])

            if abs_st_s < min_shrine_start:
                min_shrine_start = abs_st_s

    for j, st_t in enumerate(temples - start):
        abs_st_t = abs(st_t)

        if abs_st_t < min_temple_start:
            abs_st_t += np.min(dist[:,j])

            if abs_st_t < min_temple_start:
                min_temple_start = abs_st_t
    
    answers.append(min(min_shrine_start,min_temple_start))


for ans in answers:
    print(ans)

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

s,t,q = list(map(int, input().split()))
shrines = []
temples = []
questions = []
answers = []
dist = np.empty((s,t),dtype='int32')

for _ in range(s):
    shrines.append(int(input()))
shrines = np.array(shrines)

for _ in range(t):
    temples.append(int(input()))
temples = np.array(temples)

for _ in range(q):
    questions.append(int(input()))


for i, shrine in enumerate(shrines):
    dist[i]= [abs(shrine - temple) for temple in temples]

for start in questions:
    min_shrine_start = float('inf')
    min_temple_start = float('inf')

    for i, st_s in enumerate(shrines - start):
        abs_st_s = abs(st_s)

        if abs_st_s < min_shrine_start:
            abs_st_s += np.min(dist[i])

            if abs_st_s < min_shrine_start:
                min_shrine_start = abs_st_s

    for j, st_t in enumerate(temples - start):
        abs_st_t = abs(st_t)

        if abs_st_t < min_temple_start:
            abs_st_t += np.min(dist[:,j])

            if abs_st_t < min_temple_start:
                min_temple_start = abs_st_t
    
    answers.append(min(min_shrine_start,min_temple_start))


for ans in answers:
    print(ans)