結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,628 KB
testcase_01 AC 96 ms
71,976 KB
testcase_02 AC 96 ms
71,760 KB
testcase_03 AC 95 ms
71,660 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 390 ms
85,140 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 95 ms
71,824 KB
testcase_27 AC 93 ms
71,708 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 93 ms
71,768 KB
testcase_32 AC 95 ms
71,824 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 322 ms
201,036 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()
gij = gi*w+gj
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

def push(nij, dir):
    ns = move[s][dir]
    if dp[nij][ns] == -1 and aa[nij]:
        q.append((nij, ns))
        dp[nij][ns] = dist+1

while q and dp[gij][0] == -1:
    ij, s = q.popleft()
    i, j = divmod(ij, w)
    dist = dp[ij][s]
    if i: push(ij-w, 1)
    if i+1 < h: push(ij+w, 3)
    if j: push(ij-1, 2)
    if j+1 < w: push(ij+1, 0)

print(dp[gij][0])
0