結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2023-01-12 00:01:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 1,077 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 69,248 KB |
最終ジャッジ日時 | 2024-12-22 17:33:11 |
合計ジャッジ時間 | 2,622 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
from collections import dequeD = [(1, 0), (0, 1), (-1, 0), (0, -1)]DD = [(2, 0), (0, 2), (-2, 0), (0, -2)]h, w = map(int, input().split())si, sj, gi, gj = map(int, input().split())si -= 1sj -= 1gi -= 1gj -= 1B = [list(map(int, list(input()))) for _ in range(h)]visited = [[False for _ in range(w)] for _ in range(h)]visited[si][sj] = TrueQue = deque([(si, sj)])while Que:ci, cj = Que.popleft()if ci == gi and cj == gj:print("YES")exit()for di, dj in D:ni = ci + dinj = cj + djif 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:if abs(B[ci][cj] - B[ni][nj]) <= 1:visited[ni][nj] = TrueQue.append((ni, nj))for di, dj in DD:ni = ci + dinj = cj + djif 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:mi = (ci + ni) // 2mj = (cj + nj) // 2if B[ci][cj] == B[ni][nj] and B[ci][cj] > B[mi][mj]:visited[ni][nj] = TrueQue.append((ni, nj))print("NO")