結果

問題 No.2731 Two Colors
ユーザー rarpipipirarpipipi
提出日時 2024-04-20 10:47:10
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,039 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 240,464 KB
最終ジャッジ日時 2024-04-20 10:47:20
合計ジャッジ時間 9,758 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify,heappop,heappush

h,w=map(int,input().split())

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

colored0=set([(0,0)])
colored1=set([(h-1,w-1)])

que0=[]
que1=[]
heappush(que0,(a[0][1],0,1))
heappush(que0,(a[1][0],1,0))
heappush(que1,(a[h-1][w-2],h-1,w-2))
heappush(que1,(a[h-2][w-1],h-2,w-1))
que=[que0,que1]
colored=[colored0,colored1]
walk=[
    (1,0),
    (-1,0),
    (0,1),
    (0,-1),
]
def inside(y,x):
    return 0<=y<h and 0<=x<w

for i in range(h*w):
    t_que=que[i%2]
    t_colored=colored[i%2]
    o_colored=colored[(i%2)^1]
    while t_que:
        _,y,x=heappop(t_que)
        if (y,x) not in t_colored:
            break
    t_colored.add((y,x))
    # 隣がo_coloredで塗られている場合exit
    for iy,ix in walk:
        ny,nx=iy+y,ix+x
        if (ny,nx) in o_colored:
            print(i+1)
            exit()

    for iy,ix in walk:
        ny,nx=iy+y,ix+x
        if inside(ny,nx):
            if not (ny,nx) in t_colored:
                heappush(t_que,(a[ny][nx],ny,nx))






0