結果

問題 No.2731 Two Colors
ユーザー nikoro256nikoro256
提出日時 2024-04-19 22:06:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 793 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 112,492 KB
最終ジャッジ日時 2024-04-19 22:07:32
合計ジャッジ時間 17,673 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 107 ms
76,672 KB
testcase_04 WA -
testcase_05 AC 124 ms
77,568 KB
testcase_06 AC 211 ms
81,664 KB
testcase_07 WA -
testcase_08 AC 112 ms
77,356 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 264 ms
86,844 KB
testcase_15 AC 112 ms
76,988 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 103 ms
76,944 KB
testcase_26 AC 385 ms
95,360 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 256 ms
84,736 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 37 ms
52,480 KB
testcase_34 AC 37 ms
52,992 KB
testcase_35 AC 36 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
H,W=map(int,input().split())
A=[]
for _ in range(H):
    A.append(list(map(int,input().split())))
hq=[[] for _ in range(2)]
heapq.heappush(hq[0],(A[0][0],0,0))
heapq.heappush(hq[1],(A[-1][-1],H-1,W-1))
use=[[-1]*W for _ in range(H)]
d=[[1,0],[-1,0],[0,1],[0,-1]]
flag=[[False]*W for _ in range(H)]
count=0
while True:
    p,x,y=heapq.heappop(hq[count%2])
    if use[x][y]!=-1:
        continue
    use[x][y]=count%2
    for x_d,y_d in d:
        x_m=x+x_d
        y_m=y+y_d
        if 0<=x_m<H and 0<=y_m<W :
            if use[x_m][y_m]==1-count%2:
                print(count-1)
                exit(0)
            elif use[x_m][y_m]==-1 and (not flag[x_m][y_m]):
                heapq.heappush(hq[count%2],(A[x_m][y_m],x_m,y_m))
                flag[x_m][y_m]=True
    count+=1
0