結果

問題 No.1572 XI
ユーザー mkawa2mkawa2
提出日時 2021-06-27 14:08:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,828 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 244,404 KB
最終ジャッジ日時 2023-09-07 17:45:44
合計ジャッジ時間 29,553 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,652 KB
testcase_01 AC 94 ms
71,792 KB
testcase_02 AC 95 ms
71,724 KB
testcase_03 AC 96 ms
71,652 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 315 ms
83,516 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 94 ms
71,412 KB
testcase_27 AC 94 ms
71,708 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 94 ms
71,764 KB
testcase_32 AC 95 ms
71,820 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 320 ms
200,624 KB
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from collections import deque

move = [[1, 5, 3, 4],
        [2, 1, 0, 1],
        [3, 4, 1, 5],
        [0, 3, 2, 3],
        [4, 0, 4, 2],
        [5, 2, 5, 0]]

h, w = LI()
si, sj = LI1()
gi, gj = LI1()
aa = [a == "." for _ in range(h) for a in SI()]

dp = [[-1]*6 for _ in range(h*w)]
q = deque()
q.append((si*w+sj, 0))
dp[si*w+si][0] = 0
while q and dp[gi*w+gj][0] == -1:
    ij, s = q.popleft()
    i, j = divmod(ij, w)
    if i:
        nij = ij-w
        ns = move[s][1]
        if dp[nij][ns] == -1 and aa[nij]:
            q.append((nij, ns))
            dp[nij][ns] = dp[ij][s]+1
    if i+1 < h:
        nij = ij+w
        ns = move[s][3]
        if dp[nij][ns] == -1 and aa[nij]:
            q.append((nij, ns))
            dp[nij][ns] = dp[ij][s]+1
    if j:
        nij = ij-1
        ns = move[s][2]
        if dp[nij][ns] == -1 and aa[nij]:
            q.append((nij, ns))
            dp[nij][ns] = dp[ij][s]+1
    if j+1 < w:
        nij = ij+1
        ns = move[s][0]
        if dp[nij][ns] == -1 and aa[nij]:
            q.append((nij, ns))
            dp[nij][ns] = dp[ij][s]+1

print(dp[gi*w+gj][0])
0