結果

問題 No.1572 XI
ユーザー mkawa2mkawa2
提出日時 2021-06-27 14:23:36
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,430 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 246,572 KB
最終ジャッジ日時 2023-09-07 17:49:26
合計ジャッジ時間 38,214 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,628 KB
testcase_01 AC 98 ms
71,624 KB
testcase_02 AC 99 ms
71,588 KB
testcase_03 AC 99 ms
71,784 KB
testcase_04 AC 689 ms
114,204 KB
testcase_05 AC 1,406 ms
167,864 KB
testcase_06 AC 1,255 ms
174,284 KB
testcase_07 AC 401 ms
84,816 KB
testcase_08 AC 500 ms
148,268 KB
testcase_09 AC 868 ms
122,688 KB
testcase_10 AC 697 ms
137,240 KB
testcase_11 AC 500 ms
88,608 KB
testcase_12 AC 757 ms
111,052 KB
testcase_13 AC 496 ms
90,200 KB
testcase_14 AC 710 ms
111,076 KB
testcase_15 AC 337 ms
86,500 KB
testcase_16 AC 641 ms
106,788 KB
testcase_17 AC 316 ms
82,872 KB
testcase_18 AC 197 ms
106,616 KB
testcase_19 AC 661 ms
152,740 KB
testcase_20 AC 607 ms
128,448 KB
testcase_21 AC 1,255 ms
183,032 KB
testcase_22 AC 1,388 ms
165,296 KB
testcase_23 AC 225 ms
80,784 KB
testcase_24 AC 98 ms
71,632 KB
testcase_25 AC 98 ms
71,660 KB
testcase_26 AC 99 ms
71,320 KB
testcase_27 AC 98 ms
71,612 KB
testcase_28 AC 98 ms
71,708 KB
testcase_29 AC 98 ms
71,608 KB
testcase_30 AC 98 ms
71,748 KB
testcase_31 AC 98 ms
71,552 KB
testcase_32 AC 97 ms
71,292 KB
testcase_33 AC 98 ms
71,596 KB
testcase_34 AC 737 ms
206,240 KB
testcase_35 AC 640 ms
204,832 KB
testcase_36 AC 1,111 ms
217,564 KB
testcase_37 TLE -
testcase_38 AC 1,588 ms
230,944 KB
testcase_39 AC 1,406 ms
225,372 KB
testcase_40 AC 856 ms
206,752 KB
testcase_41 AC 1,614 ms
227,976 KB
testcase_42 TLE -
testcase_43 AC 1,312 ms
222,660 KB
testcase_44 AC 814 ms
219,964 KB
testcase_45 AC 1,717 ms
242,768 KB
testcase_46 AC 1,635 ms
243,500 KB
testcase_47 AC 328 ms
200,772 KB
testcase_48 AC 1,565 ms
238,452 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 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