結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2021-02-23 06:13:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 63 ms / 2,000 ms |
| コード長 | 756 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 68,224 KB |
| 最終ジャッジ日時 | 2024-09-22 02:50:18 |
| 合計ジャッジ時間 | 2,210 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
h,w = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
b = [list(map(int,input())) for _ in range(h)]
dist = [[-1]*w for _ in range(h)]
dist[sx-1][sy-1] = 1
q = [(sx-1,sy-1)]
while q:
sx,sy = q.pop()
for nx,ny in [(sx-1,sy),(sx+1,sy),(sx,sy-1),(sx,sy+1)]:
if 0 <= nx < h and 0 <= ny < w and dist[nx][ny]==-1:
if abs(b[nx][ny] - b[sx][sy]) <= 1:
q.append((nx,ny))
dist[nx][ny] = 1
for nx,ny in [(sx-2,sy),(sx+2,sy),(sx,sy-2),(sx,sy+2)]:
if 0 <= nx < h and 0 <= ny < w and dist[nx][ny]==-1:
if b[nx][ny] == b[sx][sy] > b[(nx+sx)//2][(ny+sy)//2]:
q.append((nx,ny))
dist[nx][ny] = 1
print("YES" if dist[gx-1][gy-1]==1 else "NO")
convexineq