結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
77,528 KB
testcase_01 WA -
testcase_02 AC 101 ms
71,508 KB
testcase_03 AC 128 ms
77,364 KB
testcase_04 AC 108 ms
76,648 KB
testcase_05 AC 106 ms
76,596 KB
testcase_06 AC 98 ms
71,764 KB
testcase_07 AC 100 ms
71,324 KB
testcase_08 AC 99 ms
71,524 KB
testcase_09 AC 98 ms
71,428 KB
testcase_10 AC 99 ms
71,484 KB
testcase_11 AC 99 ms
71,568 KB
testcase_12 AC 99 ms
71,652 KB
testcase_13 AC 99 ms
71,652 KB
testcase_14 AC 102 ms
71,716 KB
testcase_15 AC 99 ms
71,296 KB
testcase_16 AC 111 ms
77,024 KB
testcase_17 AC 98 ms
71,600 KB
testcase_18 AC 98 ms
71,584 KB
testcase_19 AC 99 ms
71,712 KB
testcase_20 AC 111 ms
76,856 KB
testcase_21 AC 101 ms
71,476 KB
testcase_22 AC 100 ms
71,524 KB
testcase_23 AC 105 ms
76,872 KB
testcase_24 AC 106 ms
76,876 KB
testcase_25 AC 107 ms
76,660 KB
testcase_26 AC 105 ms
76,704 KB
testcase_27 AC 105 ms
76,812 KB
testcase_28 AC 107 ms
76,876 KB
testcase_29 AC 108 ms
76,668 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(10)])
    D = [[[None]*W for i in range(H)] for j in range(10)]
    for i in range(10):
        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