結果
問題 |
No.124 門松列(3)
|
ユーザー |
|
提出日時 | 2022-02-28 21:51:19 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 853 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 68,608 KB |
最終ジャッジ日時 | 2024-07-07 01:08:21 |
合計ジャッジ時間 | 2,458 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | RE * 26 |
ソースコード
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(1, 11)]) D = [[[None]*W for i in range(H)] for j in range(1, 11)] for i in range(1, 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()