結果

問題 No.424 立体迷路
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-13 19:16:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 86,760 KB
実行使用メモリ 77,644 KB
最終ジャッジ日時 2023-08-20 20:44:35
合計ジャッジ時間 4,236 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,644 KB
testcase_01 AC 77 ms
71,352 KB
testcase_02 AC 77 ms
71,416 KB
testcase_03 AC 78 ms
71,388 KB
testcase_04 AC 81 ms
71,632 KB
testcase_05 AC 75 ms
71,336 KB
testcase_06 AC 78 ms
71,392 KB
testcase_07 AC 79 ms
71,756 KB
testcase_08 AC 75 ms
71,072 KB
testcase_09 AC 76 ms
71,724 KB
testcase_10 AC 76 ms
71,284 KB
testcase_11 AC 84 ms
71,348 KB
testcase_12 AC 79 ms
71,260 KB
testcase_13 AC 78 ms
71,440 KB
testcase_14 AC 78 ms
71,392 KB
testcase_15 AC 76 ms
71,336 KB
testcase_16 AC 78 ms
71,296 KB
testcase_17 AC 78 ms
71,648 KB
testcase_18 AC 77 ms
71,228 KB
testcase_19 AC 79 ms
71,388 KB
testcase_20 AC 78 ms
71,764 KB
testcase_21 AC 78 ms
71,060 KB
testcase_22 AC 80 ms
71,664 KB
testcase_23 AC 78 ms
71,456 KB
testcase_24 AC 134 ms
77,640 KB
testcase_25 AC 102 ms
77,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

h,w = map(int,input().split())
sl,sr,gl,gr = map(int,input().split())
grid = [input() for i in range(h)]
ans = [[0]*w for i in range(h)]

l=[1,0,-1,0]
r=[0,1,0,-1]
ll =[2,0,-2,0]
rr=[0,2,0,-2]

d=deque()
d.append((sl-1,sr-1))

while d:
    x,y=d.popleft()

    for i in range(4):
        if 0 <= x+l[i] < h and 0<= y+r[i] <w:
            if abs(int(grid[x][y]) - int(grid[x+l[i]][y+r[i]])) <= 1:
                if ans[x+l[i]][y+r[i]] == 0:
                    d.append((x+l[i],y+r[i]))
                    ans[x+l[i]][y+r[i]] = 1

    for i in range(4):
        if 0 <= x+ll[i] < h and 0<= y+rr[i] <w:
            if grid[x][y] == grid[x+ll[i]][y+rr[i]] and grid[x][y] > grid[x+l[i]][y+r[i]]:
                if ans[x+ll[i]][y+rr[i]] == 0:
                    d.append((x+ll[i],y+rr[i]))
                    ans[x+ll[i]][y+rr[i]] = 1


if ans[gl-1][gr-1] == 1:
    print('YES')
else:
    print('NO')

# for i in ans:
#     print(i)
0