結果

問題 No.424 立体迷路
ユーザー kichirb3
提出日時 2018-03-20 10:18:00
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 2,181 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-07-05 07:15:24
合計ジャッジ時間 1,404 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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

# -*- coding: utf-8 -*-
"""
No.424
https://yukicoder.me/problems/no/424
"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline
def bfs(maze, sx, sy, gx, gy, h, w):
explored = [[False] * w for _ in range(h)] #
Q = deque()
Q.append((sx, sy))
while Q:
cx, cy = Q.popleft() #
ch = maze[cy][cx] #
# ±1
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
for i in range(len(dx)):
nx = cx + dx[i]
ny = cy + dy[i]
if (0 <= nx < w) and (0 <= ny < h) and explored[ny][nx] is False:
nh = maze[ny][nx] #
if ch-1 <= nh <= ch+1:
if nx == gx and ny == gy:
return 'YES'
Q.append((nx, ny))
explored[ny][nx] = True
# 2
dx = [0, 0, -2, 2]
dy = [-2, 2, 0, 0]
for i in range(len(dx)):
nx = cx + dx[i]
ny = cy + dy[i]
if (0 <= nx < w) and (0 <= ny < h) and explored[ny][nx] is False:
nh = maze[ny][nx] #
mh = maze[(ny+cy)//2][(nx+cx)//2] #
if nh == ch and mh <= ch:
if nx == gx and ny == gy:
return 'YES'
Q.append((nx, ny))
explored[ny][nx] = True
return 'NO'
def main(args):
h, w = map(int, input().split())
sy, sx, gy, gx = map(int, input().split()) # hxwy
maze = []
for _ in range(h):
maze.append([int(x) for x in list(input().strip())])
ans = bfs(maze, sx-1, sy-1, gx-1, gy-1, h, w) # 1-1
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0