結果

問題 No.1572 XI
ユーザー mkawa2mkawa2
提出日時 2021-06-27 14:30:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,835 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 178,176 KB
最終ジャッジ日時 2023-09-07 17:53:26
合計ジャッジ時間 34,030 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,676 KB
testcase_01 AC 96 ms
71,860 KB
testcase_02 AC 97 ms
71,640 KB
testcase_03 AC 96 ms
71,652 KB
testcase_04 AC 639 ms
101,576 KB
testcase_05 AC 1,291 ms
136,636 KB
testcase_06 AC 1,172 ms
132,156 KB
testcase_07 AC 411 ms
83,408 KB
testcase_08 AC 414 ms
137,032 KB
testcase_09 AC 817 ms
105,764 KB
testcase_10 AC 642 ms
124,988 KB
testcase_11 AC 498 ms
85,804 KB
testcase_12 AC 752 ms
99,484 KB
testcase_13 AC 494 ms
86,492 KB
testcase_14 AC 677 ms
98,360 KB
testcase_15 AC 335 ms
83,756 KB
testcase_16 AC 604 ms
95,728 KB
testcase_17 AC 316 ms
81,900 KB
testcase_18 AC 165 ms
103,504 KB
testcase_19 AC 573 ms
137,980 KB
testcase_20 AC 546 ms
115,884 KB
testcase_21 AC 1,136 ms
137,824 KB
testcase_22 AC 1,308 ms
131,760 KB
testcase_23 AC 224 ms
80,616 KB
testcase_24 AC 95 ms
71,860 KB
testcase_25 AC 96 ms
71,872 KB
testcase_26 AC 96 ms
71,352 KB
testcase_27 AC 97 ms
71,796 KB
testcase_28 AC 97 ms
71,672 KB
testcase_29 AC 98 ms
71,848 KB
testcase_30 AC 95 ms
71,400 KB
testcase_31 AC 98 ms
71,780 KB
testcase_32 AC 98 ms
71,632 KB
testcase_33 AC 99 ms
71,728 KB
testcase_34 AC 603 ms
152,804 KB
testcase_35 AC 504 ms
152,532 KB
testcase_36 AC 975 ms
153,872 KB
testcase_37 AC 1,814 ms
178,176 KB
testcase_38 AC 1,425 ms
162,736 KB
testcase_39 AC 1,215 ms
154,752 KB
testcase_40 AC 727 ms
151,528 KB
testcase_41 AC 1,371 ms
159,928 KB
testcase_42 AC 1,835 ms
177,648 KB
testcase_43 AC 1,146 ms
156,052 KB
testcase_44 AC 676 ms
165,336 KB
testcase_45 AC 1,559 ms
168,292 KB
testcase_46 AC 1,454 ms
171,952 KB
testcase_47 AC 190 ms
165,216 KB
testcase_48 AC 1,371 ms
166,536 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]*h*w for _ in range(6)]
q = deque()
q.append((si*w+sj, 0))
dp[0][si*w+sj] = 0

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

while q:
    ij, s = q.popleft()
    i, j = divmod(ij, w)
    dist = dp[s][ij]
    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