結果

問題 No.424 立体迷路
ユーザー convexineqconvexineq
提出日時 2021-02-23 06:13:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 81,600 KB
実行使用メモリ 68,604 KB
最終ジャッジ日時 2023-10-22 01:29:42
合計ジャッジ時間 3,573 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,464 KB
testcase_01 AC 39 ms
53,464 KB
testcase_02 AC 38 ms
53,464 KB
testcase_03 AC 37 ms
53,464 KB
testcase_04 AC 39 ms
53,464 KB
testcase_05 AC 38 ms
53,464 KB
testcase_06 AC 38 ms
53,464 KB
testcase_07 AC 37 ms
53,464 KB
testcase_08 AC 37 ms
53,464 KB
testcase_09 AC 38 ms
53,464 KB
testcase_10 AC 37 ms
53,464 KB
testcase_11 AC 37 ms
53,464 KB
testcase_12 AC 38 ms
53,464 KB
testcase_13 AC 38 ms
53,464 KB
testcase_14 AC 38 ms
53,464 KB
testcase_15 AC 38 ms
53,464 KB
testcase_16 AC 38 ms
53,464 KB
testcase_17 AC 43 ms
59,468 KB
testcase_18 AC 42 ms
59,468 KB
testcase_19 AC 42 ms
59,468 KB
testcase_20 AC 41 ms
59,468 KB
testcase_21 AC 38 ms
53,464 KB
testcase_22 AC 38 ms
53,464 KB
testcase_23 AC 38 ms
53,464 KB
testcase_24 AC 63 ms
68,588 KB
testcase_25 AC 64 ms
68,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
b = [list(map(int,input())) for _ in range(h)]

dist = [[-1]*w for _ in range(h)]
dist[sx-1][sy-1] = 1
q = [(sx-1,sy-1)]
while q:
    sx,sy = q.pop()
    for nx,ny in [(sx-1,sy),(sx+1,sy),(sx,sy-1),(sx,sy+1)]:
        if 0 <= nx < h and 0 <= ny < w and dist[nx][ny]==-1:
            if abs(b[nx][ny] - b[sx][sy]) <= 1:
                q.append((nx,ny))
                dist[nx][ny] = 1
    for nx,ny in [(sx-2,sy),(sx+2,sy),(sx,sy-2),(sx,sy+2)]:
        if 0 <= nx < h and 0 <= ny < w and dist[nx][ny]==-1:
            if b[nx][ny] == b[sx][sy] > b[(nx+sx)//2][(ny+sy)//2]:
                q.append((nx,ny))
                dist[nx][ny] = 1
print("YES" if dist[gx-1][gy-1]==1 else "NO")
0