結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2021-02-28 00:29:19 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 1,051 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-10-02 18:06:07 |
合計ジャッジ時間 | 2,168 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
h, w = map(int, input().split())sx, sy, gx, gy = map(lambda x: int(x) - 1, input().split())b = [list(map(int, input())) for _ in range(h)]movable = [[False] * w for _ in range(h)]movable[sx][sy] = Trueq = [(sx, sy)]while q:x, y = q.pop()for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:nx, ny = x + dx, y + dyif nx < 0 or nx >= h or ny < 0 or ny >= w:continueif movable[nx][ny]:continueif abs(b[nx][ny] - b[x][y]) > 1:continuemovable[nx][ny] = Trueq.append((nx, ny))for dx, dy in [(-2, 0), (2, 0), (0, -2), (0, 2)]:nx, ny = x + dx, y + dymx, my = x + dx // 2, y + dy // 2if nx < 0 or nx >= h or ny < 0 or ny >= w:continueif movable[nx][ny]:continueif b[nx][ny] != b[x][y]:continueif b[mx][my] >= b[x][y]:continuemovable[nx][ny] = Trueq.append((nx, ny))if movable[gx][gy]:print('YES')else:print('NO')