結果

問題 No.124 門松列(3)
ユーザー 👑 colognecologne
提出日時 2022-02-28 21:45:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 877 bytes
コンパイル時間 1,976 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 77,688 KB
最終ジャッジ日時 2023-09-21 06:36:55
合計ジャッジ時間 4,925 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
77,508 KB
testcase_01 WA -
testcase_02 AC 92 ms
71,584 KB
testcase_03 AC 119 ms
77,604 KB
testcase_04 AC 115 ms
77,688 KB
testcase_05 AC 99 ms
76,764 KB
testcase_06 AC 92 ms
71,520 KB
testcase_07 AC 93 ms
71,308 KB
testcase_08 AC 93 ms
71,724 KB
testcase_09 AC 90 ms
71,676 KB
testcase_10 AC 94 ms
71,656 KB
testcase_11 AC 93 ms
71,720 KB
testcase_12 AC 95 ms
71,636 KB
testcase_13 AC 95 ms
71,508 KB
testcase_14 AC 95 ms
71,636 KB
testcase_15 AC 94 ms
71,656 KB
testcase_16 WA -
testcase_17 AC 93 ms
71,304 KB
testcase_18 AC 94 ms
71,316 KB
testcase_19 AC 93 ms
71,528 KB
testcase_20 WA -
testcase_21 AC 96 ms
71,504 KB
testcase_22 AC 94 ms
71,612 KB
testcase_23 AC 102 ms
76,900 KB
testcase_24 AC 100 ms
76,768 KB
testcase_25 AC 102 ms
76,832 KB
testcase_26 AC 101 ms
76,680 KB
testcase_27 AC 108 ms
77,428 KB
testcase_28 AC 102 ms
76,696 KB
testcase_29 AC 99 ms
76,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


def main():
    W, H = map(int, input().split())
    M = [list(map(int, input().split())) for i in range(H)]
    Q = deque([(False, 0, 0), (True, 0, 0)])
    D = [[[None]*W for i in range(H)] for j in range(2)]
    D[0][0][0] = D[1][0][0] = 0
    while len(Q) > 0:
        b, x, y = Q.popleft()
        if (x, y) == (H-1, W-1):
            print(D[b][x][y])
            return
        for dx, dy in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            r, c = x + dx, y + dy
            if 0 <= r < H and 0 <= c < W and D[not b][r][c] is None:
                if b and M[x][y] >= M[r][c]:
                    continue
                if (not b) and M[x][y] <= M[r][c]:
                    continue
                D[not b][r][c] = D[b][x][y] + 1
                Q.append((not b, r, c))
    print(-1)
    return


if __name__ == '__main__':
    main()
0