結果

問題 No.424 立体迷路
ユーザー 👑 rin204rin204
提出日時 2022-02-14 00:23:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 86,412 KB
実行使用メモリ 76,940 KB
最終ジャッジ日時 2023-09-11 15:45:51
合計ジャッジ時間 3,897 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,008 KB
testcase_01 AC 72 ms
70,872 KB
testcase_02 AC 71 ms
71,076 KB
testcase_03 AC 72 ms
71,012 KB
testcase_04 AC 74 ms
71,052 KB
testcase_05 AC 73 ms
71,100 KB
testcase_06 AC 72 ms
70,896 KB
testcase_07 AC 74 ms
70,728 KB
testcase_08 AC 73 ms
71,140 KB
testcase_09 AC 72 ms
70,976 KB
testcase_10 AC 71 ms
71,080 KB
testcase_11 AC 72 ms
70,784 KB
testcase_12 AC 71 ms
71,164 KB
testcase_13 AC 73 ms
71,024 KB
testcase_14 AC 71 ms
71,056 KB
testcase_15 AC 73 ms
71,032 KB
testcase_16 AC 73 ms
70,972 KB
testcase_17 AC 76 ms
75,156 KB
testcase_18 AC 76 ms
75,284 KB
testcase_19 AC 75 ms
75,180 KB
testcase_20 AC 76 ms
75,424 KB
testcase_21 AC 71 ms
71,080 KB
testcase_22 AC 73 ms
71,104 KB
testcase_23 AC 73 ms
71,116 KB
testcase_24 AC 92 ms
76,824 KB
testcase_25 AC 93 ms
76,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
B = [list(map(int, input())) for _ in range(h)]
tf = [[False] * w for _ in range(h)]
tf[sx][sy] = True
stack = [(sx, sy)]

directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]
while stack:
    x, y = stack.pop()
    for dx, dy in directions:
        nx = x + dx
        ny = y + dy
        if nx == -1 or nx == h or ny == -1 or ny == w:
            continue
        if abs(B[x][y] - B[nx][ny]) <= 1 and not tf[nx][ny]:
            tf[nx][ny] = True
            stack.append((nx, ny))
        nx2 = nx + dx
        ny2 = ny + dy
        if nx2 == -1 or nx2 == h or ny2 == -1 or ny2 == w:
            continue
        if B[x][y] == B[nx2][ny2] and B[nx][ny] < B[x][y] and not tf[nx2][ny2]:
            tf[nx2][ny2] = True
            stack.append((nx2, ny2))

if tf[gx][gy]:
    print("YES")
else:
    print("NO")
0