結果

問題 No.2731 Two Colors
ユーザー nikoro256nikoro256
提出日時 2024-04-19 22:08:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,530 ms / 3,000 ms
コード長 831 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 119,056 KB
最終ジャッジ日時 2024-04-19 22:09:09
合計ジャッジ時間 17,348 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,498 ms
119,056 KB
testcase_01 AC 1,530 ms
118,904 KB
testcase_02 AC 1,468 ms
118,964 KB
testcase_03 AC 103 ms
76,800 KB
testcase_04 AC 130 ms
78,848 KB
testcase_05 AC 130 ms
77,824 KB
testcase_06 AC 251 ms
83,584 KB
testcase_07 AC 190 ms
83,292 KB
testcase_08 AC 117 ms
77,836 KB
testcase_09 AC 417 ms
103,656 KB
testcase_10 AC 105 ms
77,056 KB
testcase_11 AC 787 ms
110,536 KB
testcase_12 AC 399 ms
103,824 KB
testcase_13 AC 683 ms
105,344 KB
testcase_14 AC 256 ms
88,448 KB
testcase_15 AC 125 ms
77,440 KB
testcase_16 AC 370 ms
89,528 KB
testcase_17 AC 364 ms
92,928 KB
testcase_18 AC 168 ms
78,620 KB
testcase_19 AC 356 ms
90,140 KB
testcase_20 AC 273 ms
93,260 KB
testcase_21 AC 173 ms
79,252 KB
testcase_22 AC 571 ms
107,904 KB
testcase_23 AC 233 ms
83,640 KB
testcase_24 AC 171 ms
79,348 KB
testcase_25 AC 125 ms
76,288 KB
testcase_26 AC 400 ms
100,360 KB
testcase_27 AC 499 ms
106,500 KB
testcase_28 AC 491 ms
97,224 KB
testcase_29 AC 212 ms
82,060 KB
testcase_30 AC 260 ms
86,024 KB
testcase_31 AC 248 ms
83,352 KB
testcase_32 AC 791 ms
117,844 KB
testcase_33 AC 38 ms
52,608 KB
testcase_34 AC 37 ms
52,608 KB
testcase_35 AC 38 ms
52,608 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)] for _ in range(2)]
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[count%2][x_m][y_m]):
                heapq.heappush(hq[count%2],(A[x_m][y_m],x_m,y_m))
                flag[count%2][x_m][y_m]=True
    count+=1
0