結果

問題 No.424 立体迷路
ユーザー O2MTO2MT
提出日時 2020-12-19 17:05:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 81,804 KB
実行使用メモリ 68,280 KB
最終ジャッジ日時 2023-10-21 09:22:48
合計ジャッジ時間 2,852 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,372 KB
testcase_01 AC 46 ms
55,372 KB
testcase_02 AC 45 ms
55,372 KB
testcase_03 AC 46 ms
55,372 KB
testcase_04 AC 46 ms
55,372 KB
testcase_05 AC 45 ms
55,372 KB
testcase_06 AC 44 ms
55,372 KB
testcase_07 AC 44 ms
55,372 KB
testcase_08 AC 44 ms
55,372 KB
testcase_09 AC 46 ms
55,372 KB
testcase_10 AC 45 ms
55,372 KB
testcase_11 AC 45 ms
55,372 KB
testcase_12 AC 45 ms
55,372 KB
testcase_13 AC 44 ms
55,372 KB
testcase_14 AC 45 ms
55,372 KB
testcase_15 AC 45 ms
55,372 KB
testcase_16 AC 45 ms
55,372 KB
testcase_17 AC 48 ms
58,688 KB
testcase_18 AC 47 ms
58,688 KB
testcase_19 AC 48 ms
58,688 KB
testcase_20 AC 48 ms
58,688 KB
testcase_21 AC 44 ms
55,372 KB
testcase_22 AC 45 ms
55,372 KB
testcase_23 AC 46 ms
55,372 KB
testcase_24 AC 50 ms
60,736 KB
testcase_25 AC 70 ms
68,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
H,W = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
B = [list(str(input())) for _ in range(H)]
visited = [[0 for _ in range(W)] for _ in range(H)]
visited[sx][sy] = 1
que = deque([(sx,sy,int(B[sx][sy]))])
move = [(-1,0),(0,-1),(1,0),(0,1)]
while que:
    x,y,z = que.pop()
    if x == gx and y == gy:
        print("YES")
        exit()
    for i,j in move:
        h,w = x+i,y+j
        if 0 <= h < H and 0 <= w < W:
            if visited[h][w] == 0:
                if int(B[h][w])-1 <= z <= int(B[h][w])+1:
                    visited[h][w] = 1
                    que.append((h,w,int(B[h][w])))
                if z > int(B[h][w]):
                    h += i
                    w += j
                    if 0 <= h < H and 0 <= w < W:
                        if visited[h][w] == 0:
                            if z == int(B[h][w]):
                                visited[h][w] = 1
                                que.append((h,w,int(B[h][w])))

print("NO")
0