結果

問題 No.2731 Two Colors
ユーザー titiatitia
提出日時 2024-04-19 22:07:19
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,190 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 151,368 KB
最終ジャッジ日時 2024-04-19 22:07:52
合計ジャッジ時間 9,249 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

import sys
input = sys.stdin.readline

from heapq import heappop,heappush,heapify

H,W=map(int,input().split())

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

Q1=[]
Q2=[]
USE=[[0]*W for i in range(H)]
USE2=[[0]*W for i in range(H)]

Q1.append((A[0][1],0,1))
Q1.append((A[1][0],1,0))

Q2.append((A[H-1][W-2],H-1,W-2))
Q2.append((A[H-2][W-1],H-2,W-1))

heapify(Q1)
heapify(Q2)

USE[0][0]=1
USE2[H-1][W-1]=1
flag=0
for tt in range(10**9):
    if flag==1:
        break
    if tt%2==0:
        while True:
            _,x,y=heappop(Q1)
            if USE[x][y]==1:
                continue
            USE[x][y]=1
            break

        for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
            if 0<=z<H and 0<=w<W:
                heappush(Q1,(A[z][w],z,w))
                if USE2[z][w]==1:
                    flag=1
    else:
        while True:
            _,x,y=heappop(Q2)
            if USE2[x][y]==1:
                continue
            USE2[x][y]=1
            break


        for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
            if 0<=z<H and 0<=w<W:
                heappush(Q2,(A[z][w],z,w))
                if USE[z][w]==1:
                    flag=1
print(tt)
0