結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-02-28 20:36:04 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,027 bytes |
| コンパイル時間 | 270 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-10-02 21:56:45 |
| 合計ジャッジ時間 | 1,893 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
H, W = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
G = [tuple(map(int, list(input()))) for _ in range(H)]
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]
vis = [[0] * W for _ in range(H)]
vis[sx][sy] = 1
q = [(sx, sy)]
while q:
x, y = q.pop()
now = G[x][y]
for dx, dy in zip(DX, DY):
nx = x + dx
ny = y + dy
if 0 <= nx < H and 0 <= ny < W:
if not vis[nx][ny]:
nxt = G[nx][ny]
if abs(nxt - now) <= 1:
vis[nx][ny] = 1
q.append((nx, ny))
nnx = nx + dx
nny = ny + dy
if 0 <= nnx < H and 0 <= nny < W:
if not vis[nnx][nny]:
nxt = G[nx][ny]
nxtnxt = G[nnx][nny]
if now == nxtnxt and now > nxt:
vis[nnx][nny] = 1
q.append((nnx, nny))
if vis[gx][gy]:
print("YES")
else:
print("NO")
tktk_snsn