結果

問題 No.424 立体迷路
ユーザー ronpooronpoo
提出日時 2023-08-28 16:56:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 1,800 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 77,804 KB
最終ジャッジ日時 2023-08-28 16:56:41
合計ジャッジ時間 4,939 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,860 KB
testcase_01 AC 92 ms
71,712 KB
testcase_02 AC 92 ms
71,560 KB
testcase_03 AC 93 ms
71,624 KB
testcase_04 AC 93 ms
71,588 KB
testcase_05 AC 91 ms
71,636 KB
testcase_06 AC 92 ms
71,740 KB
testcase_07 AC 92 ms
71,592 KB
testcase_08 AC 92 ms
71,592 KB
testcase_09 AC 93 ms
71,592 KB
testcase_10 AC 93 ms
71,720 KB
testcase_11 AC 91 ms
71,736 KB
testcase_12 AC 100 ms
71,464 KB
testcase_13 AC 91 ms
71,632 KB
testcase_14 AC 91 ms
71,732 KB
testcase_15 AC 92 ms
71,436 KB
testcase_16 AC 93 ms
71,584 KB
testcase_17 AC 93 ms
71,752 KB
testcase_18 AC 91 ms
71,540 KB
testcase_19 AC 99 ms
71,660 KB
testcase_20 AC 93 ms
71,764 KB
testcase_21 AC 91 ms
71,724 KB
testcase_22 AC 92 ms
71,600 KB
testcase_23 AC 92 ms
71,544 KB
testcase_24 AC 154 ms
77,432 KB
testcase_25 AC 124 ms
77,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

way = [(-1, 0), (1, 0), (0, -1), (0, 1)]
dist = [[float('inf')]*w for _ in range(h)]
dist[sx][sy] = 0
que = deque([(sx, sy)])
while que:
    x, y = que.popleft()
    hight = int(b[x][y])
    for i, j in way:
        nx = x + i
        ny = y + j
        if 0 <= nx < h and 0 <= ny < w:            
            nhight = int(b[nx][ny])
            if -1 <= hight - nhight <= 1 and dist[nx][ny] == float('inf'):
                dist[nx][ny] = dist[x][y] + 1
                que.append((nx, ny))
        nx += i
        ny += j
        if 0 <= nx < h and 0 <= ny < w:
            nhight = int(b[nx][ny])
            mhight = int(b[nx-i][ny-j])
            if mhight < hight == nhight and dist[nx][ny] == float('inf'):
                dist[nx][ny] = dist[x][y] + 1
                que.append((nx, ny))

if dist[gx][gy] != float('inf'):
    print('YES')
else:
    print('NO')
0