結果

問題 No.424 立体迷路
ユーザー Mr.FukuMr.Fuku
提出日時 2018-08-11 17:31:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 8,480 KB
最終ジャッジ日時 2023-09-18 17:05:23
合計ジャッジ時間 1,863 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,276 KB
testcase_01 AC 16 ms
8,328 KB
testcase_02 AC 17 ms
8,352 KB
testcase_03 AC 17 ms
8,380 KB
testcase_04 AC 17 ms
8,428 KB
testcase_05 AC 17 ms
8,192 KB
testcase_06 AC 16 ms
8,240 KB
testcase_07 AC 17 ms
8,332 KB
testcase_08 AC 16 ms
8,228 KB
testcase_09 AC 17 ms
8,300 KB
testcase_10 AC 17 ms
8,216 KB
testcase_11 AC 17 ms
8,272 KB
testcase_12 AC 17 ms
8,232 KB
testcase_13 AC 17 ms
8,216 KB
testcase_14 AC 17 ms
8,368 KB
testcase_15 AC 17 ms
8,436 KB
testcase_16 AC 17 ms
8,244 KB
testcase_17 AC 17 ms
8,480 KB
testcase_18 AC 17 ms
8,408 KB
testcase_19 AC 18 ms
8,276 KB
testcase_20 AC 18 ms
8,032 KB
testcase_21 AC 17 ms
8,232 KB
testcase_22 AC 17 ms
8,240 KB
testcase_23 AC 17 ms
8,332 KB
testcase_24 AC 21 ms
8,280 KB
testcase_25 AC 21 ms
8,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0