結果

問題 No.1572 XI
ユーザー mkawa2mkawa2
提出日時 2021-06-27 14:25:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,455 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 245,972 KB
最終ジャッジ日時 2023-09-07 17:51:05
合計ジャッジ時間 36,035 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,724 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 94 ms
71,868 KB
testcase_04 AC 661 ms
114,056 KB
testcase_05 AC 1,355 ms
168,508 KB
testcase_06 AC 1,189 ms
175,204 KB
testcase_07 AC 389 ms
84,388 KB
testcase_08 AC 488 ms
147,592 KB
testcase_09 AC 842 ms
122,884 KB
testcase_10 AC 683 ms
137,608 KB
testcase_11 AC 483 ms
88,584 KB
testcase_12 AC 746 ms
112,376 KB
testcase_13 AC 470 ms
90,432 KB
testcase_14 AC 673 ms
112,456 KB
testcase_15 AC 328 ms
86,676 KB
testcase_16 AC 622 ms
105,836 KB
testcase_17 AC 310 ms
83,232 KB
testcase_18 AC 193 ms
106,612 KB
testcase_19 AC 643 ms
152,272 KB
testcase_20 AC 582 ms
128,732 KB
testcase_21 AC 1,231 ms
184,180 KB
testcase_22 AC 1,323 ms
164,156 KB
testcase_23 AC 219 ms
81,412 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 95 ms
71,600 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 95 ms
71,724 KB
testcase_33 AC 93 ms
71,740 KB
testcase_34 AC 720 ms
207,064 KB
testcase_35 AC 632 ms
204,236 KB
testcase_36 AC 1,073 ms
217,704 KB
testcase_37 AC 1,946 ms
245,972 KB
testcase_38 AC 1,522 ms
229,712 KB
testcase_39 AC 1,330 ms
226,268 KB
testcase_40 AC 845 ms
205,908 KB
testcase_41 AC 1,511 ms
227,280 KB
testcase_42 AC 1,976 ms
244,992 KB
testcase_43 AC 1,273 ms
221,892 KB
testcase_44 AC 805 ms
219,488 KB
testcase_45 AC 1,641 ms
241,812 KB
testcase_46 AC 1,601 ms
241,924 KB
testcase_47 AC 334 ms
201,080 KB
testcase_48 AC 1,494 ms
236,820 KB
権限があれば一括ダウンロードができます

ソースコード

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+sj][0] = 0

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

while q:
    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(-1)
0