結果

問題 No.424 立体迷路
ユーザー Mr.FukuMr.Fuku
提出日時 2018-08-11 16:29:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 871 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 11,976 KB
実行使用メモリ 10,960 KB
最終ジャッジ日時 2023-10-24 13:55:39
合計ジャッジ時間 1,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,244 KB
testcase_01 AC 29 ms
10,236 KB
testcase_02 AC 29 ms
10,236 KB
testcase_03 AC 29 ms
10,244 KB
testcase_04 AC 27 ms
10,272 KB
testcase_05 AC 27 ms
10,236 KB
testcase_06 AC 27 ms
10,236 KB
testcase_07 AC 27 ms
10,236 KB
testcase_08 AC 27 ms
10,236 KB
testcase_09 AC 27 ms
10,236 KB
testcase_10 AC 27 ms
10,240 KB
testcase_11 AC 27 ms
10,240 KB
testcase_12 AC 27 ms
10,240 KB
testcase_13 AC 28 ms
10,248 KB
testcase_14 AC 28 ms
10,244 KB
testcase_15 AC 27 ms
10,240 KB
testcase_16 AC 27 ms
10,244 KB
testcase_17 AC 28 ms
10,288 KB
testcase_18 AC 29 ms
10,292 KB
testcase_19 AC 27 ms
10,288 KB
testcase_20 AC 28 ms
10,288 KB
testcase_21 AC 27 ms
10,244 KB
testcase_22 AC 27 ms
10,252 KB
testcase_23 AC 28 ms
10,244 KB
testcase_24 RE -
testcase_25 AC 28 ms
10,288 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(h,w):
    if h==sh and w==sw:
        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
            search(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
                search(nnh,nnw)

for i in range(H):
    l = list(input())
    l = map(int,l)
    maze.append([INF]+list(l)+[INF])
maze.append([INF]*(W+2))
memo[gh][gw]=0
search(gh,gw)
print("NO")
0