結果

問題 No.1572 XI
ユーザー mkawa2mkawa2
提出日時 2021-06-27 14:26:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,926 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 246,036 KB
最終ジャッジ日時 2023-09-07 17:52:14
合計ジャッジ時間 34,882 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,816 KB
testcase_01 AC 95 ms
71,636 KB
testcase_02 AC 93 ms
71,680 KB
testcase_03 AC 92 ms
71,516 KB
testcase_04 AC 658 ms
113,716 KB
testcase_05 AC 1,317 ms
168,532 KB
testcase_06 AC 1,168 ms
174,884 KB
testcase_07 AC 389 ms
84,576 KB
testcase_08 AC 474 ms
147,700 KB
testcase_09 AC 830 ms
123,108 KB
testcase_10 AC 665 ms
137,636 KB
testcase_11 AC 485 ms
88,400 KB
testcase_12 AC 737 ms
112,232 KB
testcase_13 AC 476 ms
90,084 KB
testcase_14 AC 681 ms
112,020 KB
testcase_15 AC 326 ms
86,440 KB
testcase_16 AC 614 ms
105,584 KB
testcase_17 AC 306 ms
83,064 KB
testcase_18 AC 188 ms
106,556 KB
testcase_19 AC 634 ms
152,204 KB
testcase_20 AC 572 ms
128,532 KB
testcase_21 AC 1,187 ms
184,204 KB
testcase_22 AC 1,281 ms
164,324 KB
testcase_23 AC 216 ms
81,500 KB
testcase_24 AC 96 ms
71,604 KB
testcase_25 AC 96 ms
71,672 KB
testcase_26 AC 97 ms
71,528 KB
testcase_27 AC 95 ms
71,536 KB
testcase_28 AC 96 ms
71,732 KB
testcase_29 AC 98 ms
71,836 KB
testcase_30 AC 97 ms
71,356 KB
testcase_31 AC 96 ms
71,844 KB
testcase_32 AC 96 ms
71,540 KB
testcase_33 AC 97 ms
71,472 KB
testcase_34 AC 720 ms
206,888 KB
testcase_35 AC 616 ms
204,388 KB
testcase_36 AC 1,081 ms
217,508 KB
testcase_37 AC 1,926 ms
246,036 KB
testcase_38 AC 1,460 ms
229,464 KB
testcase_39 AC 1,257 ms
226,196 KB
testcase_40 AC 815 ms
205,476 KB
testcase_41 AC 1,410 ms
226,760 KB
testcase_42 AC 1,916 ms
244,900 KB
testcase_43 AC 1,241 ms
221,736 KB
testcase_44 AC 776 ms
219,528 KB
testcase_45 AC 1,593 ms
242,264 KB
testcase_46 AC 1,569 ms
241,536 KB
testcase_47 AC 321 ms
200,828 KB
testcase_48 AC 1,430 ms
236,684 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):
    ns = move[s][dir]
    if nij == gij and ns == 0:
        print(dist+1)
        exit()
    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