結果

問題 No.424 立体迷路
ユーザー kohei2019kohei2019
提出日時 2022-01-23 14:03:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 77,876 KB
最終ジャッジ日時 2023-08-19 18:51:30
合計ジャッジ時間 4,503 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,508 KB
testcase_01 AC 95 ms
71,476 KB
testcase_02 AC 96 ms
71,476 KB
testcase_03 AC 96 ms
71,480 KB
testcase_04 AC 95 ms
71,476 KB
testcase_05 AC 94 ms
71,552 KB
testcase_06 AC 95 ms
71,492 KB
testcase_07 AC 95 ms
71,564 KB
testcase_08 AC 95 ms
71,444 KB
testcase_09 AC 95 ms
71,512 KB
testcase_10 AC 95 ms
71,360 KB
testcase_11 AC 94 ms
71,612 KB
testcase_12 AC 94 ms
71,720 KB
testcase_13 AC 94 ms
71,520 KB
testcase_14 AC 92 ms
71,688 KB
testcase_15 AC 94 ms
71,472 KB
testcase_16 AC 95 ms
71,616 KB
testcase_17 AC 100 ms
76,812 KB
testcase_18 AC 99 ms
76,892 KB
testcase_19 AC 99 ms
76,736 KB
testcase_20 AC 99 ms
76,832 KB
testcase_21 AC 94 ms
71,732 KB
testcase_22 AC 95 ms
71,532 KB
testcase_23 AC 95 ms
71,528 KB
testcase_24 AC 127 ms
77,848 KB
testcase_25 AC 122 ms
77,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
H,W = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
lshw = [list(map(int,list(input()))) for i in range(H)]
d = collections.deque([(sx,sy)])
used = [[False]*W for i in range(H)]

dxy = [(1,0),(-1,0),(0,1),(0,-1)]
dxy2 = [(2,0),(-2,0),(0,2),(0,-2)]
while d:
    x,y = d.popleft()
    if used[x][y]:
        continue
    used[x][y] = True
    for dx,dy in dxy:
        if 0 <= x+dx < H and 0 <= y+dy < W:
            if used[x+dx][y+dy]:
                continue
            if abs(lshw[x][y]-lshw[x+dx][y+dy]) <= 1:
                d.append((x+dx,y+dy))
    for k in range(4):
        dx2,dy2 = dxy2[k]
        dx,dy = dxy[k]
        if 0 <= x+dx2 < H and 0 <= y+dy2 < W:
            if used[x+dx2][y+dy2]:
                continue
            if lshw[x][y] == lshw[x+dx2][y+dy2] and lshw[x][y] > lshw[x+dx][y+dy]:
                d.append((x+dx2,y+dy2))
if used[gx][gy]:
    print('YES')
else:
    print('NO')
0