結果

問題 No.2731 Two Colors
ユーザー todosectodosec
提出日時 2024-04-26 03:01:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 873 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 73,152 KB
最終ジャッジ日時 2024-04-26 03:02:10
合計ジャッジ時間 9,768 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

from heapq import *

EMPTY = -1
H, W = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(H)]
cols = [[EMPTY] * W for _ in range(H)]
cols[0][0] = 0
cols[H - 1][W - 1] = 1

q0 = [(nums[0][1], (0, 1)), (nums[1][0], (1, 0))]
heapify(q0)

q1 = [(nums[H - 1][W - 2], (H - 1, W - 2)), (nums[H - 2][W - 1], (H - 2, W - 1))]
heapify(q1)

Q = [q0, q1]

dirs = [[0, 1], [1, 0], [-1, 0], [0, -1]]
i = 0
while 1:
    i2 = i % 2
    a, (x, y) = heappop(Q[i2])
    if cols[x][y] == EMPTY:
        cols[x][y] = i2
        for xd, yd in dirs:
            x2 = x + xd
            y2 = y + yd
            if 0 <= x2 < H and 0 <= y2 < W:
                if cols[x2][y2] == i2 ^ 1:
                    print(i + 1)
                    exit()
                elif cols[x2][y2] == EMPTY:
                    heappush(Q[i2], (nums[x2][y2], (x2, y2)))
        i += 1
0