結果

問題 No.424 立体迷路
ユーザー ntudantuda
提出日時 2024-01-03 16:10:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 860 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 66,536 KB
最終ジャッジ日時 2024-01-03 16:10:22
合計ジャッジ時間 2,826 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 48 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 37 ms
53,460 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 36 ms
53,460 KB
testcase_15 AC 37 ms
53,460 KB
testcase_16 AC 37 ms
53,460 KB
testcase_17 AC 41 ms
59,452 KB
testcase_18 AC 40 ms
59,452 KB
testcase_19 AC 41 ms
59,452 KB
testcase_20 AC 40 ms
59,452 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 58 ms
66,536 KB
testcase_25 AC 58 ms
66,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int,input().split())
SG = [i-1 for i in list(map(int,input().split()))]
S = tuple(SG[:2])
G = tuple(SG[2:])
B = [[int(s) for s in input()] for _ in range(H)]
Q = {S}
dir = [[1,0],[0,1],[-1,0],[0,-1]]
nv = [[True] * W for _ in range(H)]
nv[S[0]][S[1]] = False
while Q:
    x,y = next(iter(Q))
    if G == (x,y):
        print("YES")
        exit()
    Q.remove((x,y))
    nowh = B[x][y]
    for xd,yd in dir:
        x2 = x + xd
        y2 = y + yd
        if 0 <= x2 < H and 0 <= y2 < W:
            if nv[x2][y2] and abs(B[x2][y2] - nowh) <= 1:
                nv[x2][y2] = False
                Q.add((x2,y2))
    for xd,yd in dir:
        x2 = x + xd * 2
        y2 = y + yd * 2
        if 0 <= x2 < H and 0 <= y2 < W:
            if nv[x2][y2] and B[x2][y2] == nowh:
                nv[x2][y2] = False
                Q.add((x2,y2))

print("NO")
0