結果

問題 No.2731 Two Colors
ユーザー todosectodosec
提出日時 2024-04-26 03:10:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 895 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 59,136 KB
最終ジャッジ日時 2024-04-26 03:10:40
合計ジャッジ時間 7,841 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 31 ms
10,880 KB
testcase_34 AC 31 ms
10,880 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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]]
dipper = 0
for i in range(0,1000):
    i2 = i % 2
    a, (x, y) = heappop(Q[i2])
    dipper += 1
    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(dipper)
                    exit()
                elif cols[x2][y2] == EMPTY:
                    heappush(Q[i2], (nums[x2][y2], (x2, y2)))
0