結果

問題 No.2731 Two Colors
ユーザー nikoro256nikoro256
提出日時 2024-04-19 22:04:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 697 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 131,756 KB
最終ジャッジ日時 2024-04-19 22:05:17
合計ジャッジ時間 9,254 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 103 ms
77,372 KB
testcase_04 AC 154 ms
79,848 KB
testcase_05 AC 211 ms
79,288 KB
testcase_06 AC 279 ms
86,016 KB
testcase_07 AC 229 ms
84,104 KB
testcase_08 AC 140 ms
78,208 KB
testcase_09 AC 494 ms
103,936 KB
testcase_10 AC 121 ms
76,884 KB
testcase_11 AC 1,045 ms
129,312 KB
testcase_12 AC 510 ms
103,900 KB
testcase_13 AC 874 ms
120,320 KB
testcase_14 AC 316 ms
90,064 KB
testcase_15 AC 147 ms
78,724 KB
testcase_16 AC 424 ms
95,540 KB
testcase_17 AC 506 ms
98,304 KB
testcase_18 AC 190 ms
80,616 KB
testcase_19 AC 462 ms
96,820 KB
testcase_20 AC 298 ms
91,156 KB
testcase_21 AC 220 ms
80,268 KB
testcase_22 AC 731 ms
115,164 KB
testcase_23 AC 311 ms
87,912 KB
testcase_24 AC 214 ms
81,832 KB
testcase_25 AC 114 ms
76,756 KB
testcase_26 AC 522 ms
102,560 KB
testcase_27 AC 625 ms
109,952 KB
testcase_28 AC 582 ms
106,112 KB
testcase_29 AC 318 ms
85,760 KB
testcase_30 AC 320 ms
89,764 KB
testcase_31 AC 333 ms
88,160 KB
testcase_32 AC 1,064 ms
131,756 KB
testcase_33 AC 39 ms
52,736 KB
testcase_34 AC 38 ms
53,248 KB
testcase_35 AC 39 ms
53,248 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]]
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:
                heapq.heappush(hq[count%2],(A[x_m][y_m],x_m,y_m))
    count+=1
0