結果

問題 No.424 立体迷路
ユーザー niodachi1
提出日時 2019-10-16 10:37:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 910 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-06-11 17:50:11
合計ジャッジ時間 1,568 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys
sys.setrecursionlimit(10**6)
h, w = map(int, input().split())
s_x, s_y, g_x, g_y = map(int, input().split())
s = [s_x-1, s_y-1]
g = [g_x-1, g_y-1]
b = [list(map(int, input())) for _ in range(h)]
flg = [[False for _ in range(w)] for _ in range(h)]
def judge(cx,cy,nx,ny):
ch = b[cx][cy]
nh = b[nx][ny]
if abs(cx+cy-nx-ny) == 1:
if abs(ch-nh) <= 1:
return True
elif abs(cx+cy-nx-ny) == 2:
mh = b[(cx+nx)//2][(cy+ny)//2]
if mh < ch and mh < nh and ch == nh:
return True
def bfs(q):
cx,cy = q.pop(0)
next = [[cx+1, cy],[cx-1, cy],[cx, cy+1],[cx, cy-1],[cx+2, cy],[cx-2, cy],[cx, cy+2],[cx, cy-2]]
for nx, ny in next:
if 0 <= nx < h and 0 <= ny < w and flg[nx][ny] == False:
if judge(cx, cy, nx, ny):
flg[nx][ny] = True
q.append([nx, ny])
if len(q) == 0:
return flg[g[0]][g[1]]
return bfs(q)
q = []
q.append(s)
if bfs(q):
print("YES")
else:
print("NO")
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0