結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
Mr.Fuku
|
| 提出日時 | 2018-08-11 17:31:43 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,062 bytes |
| コンパイル時間 | 90 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-07-05 07:16:50 |
| 合計ジャッジ時間 | 1,434 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
H,W = map(int,input().split())
sh,sw,gh,gw = map(int,input().split())
INF = float("inf")
maze = [[INF]*(W+2)]
memo = [[1 for i in range(W+2)]for j in range(H+2)]
def search(stack):
lst = []
for j in stack:
h,w = j[0],j[1]
if h==gh and w==gw:
print("YES")
exit(0)
now = maze[h][w]
for i in [[1,0],[0,1],[-1,0],[0,-1]]:
nh,nw = h+i[0],w+i[1]
if memo[nh][nw] and (maze[nh][nw]==now or maze[nh][nw]==now-1 or maze[nh][nw]==now+1):
memo[nh][nw]=0
lst.append([nh,nw])
nnh,nnw = nh+i[0],nw+i[1]
if nnh>=0 and nnh<=H and nnw>0 and nnw<=W:
if maze[nh][nw]<now and maze[nnh][nnw]==now and memo[nnh][nnw]:
memo[nnh][nnw]=0
lst.append([nnh,nnw])
return lst
for i in range(H):
l = list(input())
l = map(int,l)
maze.append([INF]+list(l)+[INF])
maze.append([INF]*(W+2))
memo[sh][sw]=0
lst = search([[sh,sw]])
while lst!=[]:
lst = search(lst)
print("NO")
Mr.Fuku