結果

問題 No.2731 Two Colors
ユーザー 👑 rin204rin204
提出日時 2024-04-20 01:20:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,434 ms / 3,000 ms
コード長 846 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 119,852 KB
最終ジャッジ日時 2024-04-20 01:20:52
合計ジャッジ時間 15,604 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,327 ms
119,808 KB
testcase_01 AC 1,301 ms
119,852 KB
testcase_02 AC 1,434 ms
119,492 KB
testcase_03 AC 86 ms
77,056 KB
testcase_04 AC 107 ms
79,104 KB
testcase_05 AC 111 ms
78,832 KB
testcase_06 AC 209 ms
82,688 KB
testcase_07 AC 162 ms
83,884 KB
testcase_08 AC 91 ms
77,352 KB
testcase_09 AC 382 ms
104,028 KB
testcase_10 AC 82 ms
77,080 KB
testcase_11 AC 716 ms
110,400 KB
testcase_12 AC 382 ms
104,204 KB
testcase_13 AC 609 ms
105,624 KB
testcase_14 AC 224 ms
88,724 KB
testcase_15 AC 96 ms
77,056 KB
testcase_16 AC 310 ms
89,888 KB
testcase_17 AC 343 ms
93,696 KB
testcase_18 AC 133 ms
79,640 KB
testcase_19 AC 321 ms
89,828 KB
testcase_20 AC 247 ms
93,068 KB
testcase_21 AC 157 ms
79,348 KB
testcase_22 AC 537 ms
107,772 KB
testcase_23 AC 201 ms
84,008 KB
testcase_24 AC 136 ms
79,764 KB
testcase_25 AC 88 ms
76,800 KB
testcase_26 AC 362 ms
100,700 KB
testcase_27 AC 454 ms
106,480 KB
testcase_28 AC 425 ms
97,428 KB
testcase_29 AC 180 ms
81,832 KB
testcase_30 AC 222 ms
86,528 KB
testcase_31 AC 217 ms
83,412 KB
testcase_32 AC 745 ms
118,264 KB
testcase_33 AC 37 ms
52,480 KB
testcase_34 AC 39 ms
52,736 KB
testcase_35 AC 39 ms
52,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

hq1 = [(A[0][0], 0, 0)]
hq2 = [(A[h - 1][w - 1], h - 1, w - 1)]
used = [[False] * w for _ in range(h)]
used1 = [[False] * w for _ in range(h)]
used2 = [[False] * w for _ in range(h)]
ans = 0
used1[0][0] = True
used2[h - 1][w - 1] = True

di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]

while 1:
    ans += 1
    a, i, j = heappop(hq1)
    used[i][j] = True
    for k in range(4):
        ni, nj = i + di[k], j + dj[k]
        if ni == -1 or ni == h or nj == -1 or nj == w:
            continue
        if not used1[ni][nj]:
            if used[ni][nj]:
                print(ans - 2)
                exit()
            heappush(hq1, (A[ni][nj], ni, nj))
            used1[ni][nj] = True

    hq1, hq2 = hq2, hq1
    used1, used2 = used2, used1
0