結果

問題 No.424 立体迷路
ユーザー tokizotokizo
提出日時 2019-02-01 17:33:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,038 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-05-02 04:56:50
合計ジャッジ時間 2,786 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
12,416 KB
testcase_01 AC 52 ms
12,416 KB
testcase_02 AC 54 ms
12,416 KB
testcase_03 AC 54 ms
12,416 KB
testcase_04 AC 53 ms
12,416 KB
testcase_05 AC 53 ms
12,416 KB
testcase_06 AC 53 ms
12,416 KB
testcase_07 AC 55 ms
12,416 KB
testcase_08 AC 54 ms
12,416 KB
testcase_09 AC 55 ms
12,544 KB
testcase_10 AC 53 ms
12,416 KB
testcase_11 AC 54 ms
12,416 KB
testcase_12 AC 57 ms
12,416 KB
testcase_13 AC 54 ms
12,416 KB
testcase_14 AC 52 ms
12,416 KB
testcase_15 AC 55 ms
12,416 KB
testcase_16 AC 53 ms
12,416 KB
testcase_17 AC 54 ms
12,416 KB
testcase_18 AC 53 ms
12,416 KB
testcase_19 AC 55 ms
12,416 KB
testcase_20 AC 54 ms
12,416 KB
testcase_21 AC 53 ms
12,416 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import pprint

h, w = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1

B = []
for i in range(h):
    B.append(list(map(int, list(input()))))

seen = [[False for _ in range(w)] for _ in range(h)]

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
dx2 = [-2, 2, 0, 0]
dy2 = [0, 0, -2, 2]

def dfs(x, y):
    if x == gx and y == gy:
        return True

    seen[x][y] = True

    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if seen[nx][ny] or abs(B[x][y] - B[nx][ny]) > 1:
            continue
        if dfs(nx, ny):
            return True

    for i in range(4):
        nx = x + dx2[i]
        ny = y + dy2[i]
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if seen[nx][ny] or B[x][y] != B[nx][ny]:
            continue
        if dfs(nx, ny):
            return True
    return False

if dfs(sx, sy):
    print("YES")
else:
    print("NO")

#pprint.pprint(seen)
0