結果

問題 No.124 門松列(3)
ユーザー 👑 colognecologne
提出日時 2022-02-28 21:50:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 844 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 77,808 KB
最終ジャッジ日時 2023-09-21 06:43:02
合計ジャッジ時間 4,935 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
77,540 KB
testcase_01 AC 98 ms
71,516 KB
testcase_02 AC 96 ms
71,476 KB
testcase_03 AC 129 ms
77,808 KB
testcase_04 AC 108 ms
77,144 KB
testcase_05 AC 110 ms
77,140 KB
testcase_06 AC 100 ms
71,524 KB
testcase_07 AC 100 ms
71,532 KB
testcase_08 AC 98 ms
71,576 KB
testcase_09 AC 99 ms
71,360 KB
testcase_10 AC 98 ms
71,656 KB
testcase_11 AC 98 ms
71,432 KB
testcase_12 AC 99 ms
71,576 KB
testcase_13 AC 100 ms
71,616 KB
testcase_14 AC 98 ms
71,432 KB
testcase_15 AC 102 ms
71,612 KB
testcase_16 AC 113 ms
76,952 KB
testcase_17 AC 98 ms
71,436 KB
testcase_18 AC 99 ms
71,592 KB
testcase_19 AC 99 ms
71,428 KB
testcase_20 AC 107 ms
76,540 KB
testcase_21 AC 99 ms
71,632 KB
testcase_22 AC 100 ms
71,524 KB
testcase_23 AC 105 ms
76,672 KB
testcase_24 AC 109 ms
77,052 KB
testcase_25 AC 106 ms
76,756 KB
testcase_26 AC 106 ms
76,660 KB
testcase_27 AC 105 ms
76,656 KB
testcase_28 AC 109 ms
77,168 KB
testcase_29 AC 108 ms
77,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


def iks(a, b, c):
    return a != c and ((a < b > c) or (a > b < c))


def main():
    W, H = map(int, input().split())
    M = [list(map(int, input().split())) for i in range(H)]
    Q = deque([(i, 0, 0) for i in range(11)])
    D = [[[None]*W for i in range(H)] for j in range(11)]
    for i in range(11):
        D[i][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)]:
            bv, r, c = M[x][y], x + dx, y + dy
            if 0 <= r < H and 0 <= c < W and D[bv][r][c] is None and iks(b, M[x][y], M[r][c]):
                D[bv][r][c] = D[b][x][y] + 1
                Q.append((bv, r, c))
    print(-1)
    return


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