Problem p02579 (python)

Fixed submission:
from collections import deque
H,W = map(int, input().split())
CH,CW = map(lambda x: int(x) - 1, input().split())
DH,DW = map(lambda x: int(x) - 1, input().split())
S = [input() for i in range(H)]
INF = 10 ** 9
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]
h = CH
w = CW
Distance = [[INF] * W for _ in range(H)]
Distance[h][w] = 0
q = deque(())
q.append((h,w))
while q:
  h,w = q.popleft()
  if [h,w] == [DH,DW]:
    break
  for i,j in walk:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w]
      q.appendleft((hwalk,wwalk))
  for i,j in warp:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] + 1 < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w] + 1
      q.append((hwalk,wwalk))
print(int(Distance[DH][DW]) if Distance[DH][DW] != INF else -1)

Buggy submission (verdict: Runtime Error):
import numpy as np
from collections import deque
H,W = map(int, input().split())
CH,CW = map(int, input().split())
DH,DW = map(int, input().split())
CH = CH -1
CW = CW -1
DH = DH -1
DW = DW -1
S = np.array([list(input()) for i in range(H)])
countWarp = np.ones((H,W))*H*W
nowH = CH
nowW = CW
countWarp[CH,CW] = 0
q = deque([])
q.append([nowH,nowW])
for n in range(0,H*W):
  tmp = q.popleft()
  nowH = tmp[0]
  nowW = tmp[1]
  for i in range(-2,3):
    for j in range(-2,3):
      if nowH+i >= 0 and nowW+j >= 0 and nowH+i < H and nowW+j < W:
        if (abs(i) + abs(j)) == 1:
          if S[nowH+i,nowW+j] == '.':
            if countWarp[nowH+i,nowW+j] == H*W:
              q.append([nowH+i,nowW+j])
            countWarp[nowH+i,nowW+j] = min(countWarp[nowH,nowW],countWarp[nowH+i,nowW+j])
        if (abs(i) + abs(j)) >= 2:
          if S[nowH+i,nowW+j] == '.':
            if countWarp[nowH+i,nowW+j] == H*W:
              q.append([nowH+i,nowW+j])
            countWarp[nowH+i,nowW+j] = min(countWarp[nowH,nowW]+1,countWarp[nowH+i,nowW+j])
  if len(q) == 0:
    break
if countWarp[DH,DW] == H*W:
  print(-1)
else:
  print(int(countWarp[DH,DW]))

Buggy submission (verdict: Runtime Error):
import numpy as np
from collections import deque
H,W = map(int, input().split())
CH,CW = map(int, input().split())
DH,DW = map(int, input().split())
CH = CH -1
CW = CW -1
DH = DH -1
DW = DW -1
S = np.array([list(input()) for i in range(H)])
countWarp = np.ones((H,W))*H*W
nowH = CH
nowW = CW
countWarp[CH,CW] = 0
q = deque([])
q.append([nowH,nowW])
for n in range(0,H*W/2):
  tmp = q.popleft()
  nowH = tmp[0]
  nowW = tmp[1]
  for i in range(-2,2+1):
    for j in range(-2,2+1):
      if nowH+i >= 0 and nowW+j >= 0 and nowH+i < H and nowW+j < W:
        if abs(i) + abs(j) == 1:
          if S[nowH+i,nowW+j] == '.':
            if countWarp[nowH+i,nowW+j] == H*W:
              q.append([nowH+i,nowW+j])
            countWarp[nowH+i,nowW+j] = min(countWarp[nowH,nowW],countWarp[nowH+i,nowW+j])
        if abs(i) + abs(j) >= 2:
          if S[nowH+i,nowW+j] == '.':
            if countWarp[nowH+i,nowW+j] == H*W:
              q.append([nowH+i,nowW+j])
            countWarp[nowH+i,nowW+j] = min(countWarp[nowH,nowW]+1,countWarp[nowH+i,nowW+j])
  if len(q) == 0:
    break
if countWarp[DH,DW] == H*W:
  print(-1)
else:
  print(int(countWarp[DH,DW]))