結果

問題 No.2096 Rage With Our Friends
ユーザー mkawa2mkawa2
提出日時 2022-10-07 22:57:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,353 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 849,476 KB
最終ジャッジ日時 2023-09-03 14:50:16
合計ジャッジ時間 11,969 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,576 KB
testcase_01 AC 93 ms
71,520 KB
testcase_02 AC 94 ms
71,240 KB
testcase_03 WA -
testcase_04 AC 92 ms
71,368 KB
testcase_05 AC 93 ms
71,572 KB
testcase_06 AC 92 ms
71,712 KB
testcase_07 AC 91 ms
71,716 KB
testcase_08 AC 103 ms
76,612 KB
testcase_09 AC 95 ms
72,024 KB
testcase_10 WA -
testcase_11 AC 2,692 ms
494,280 KB
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# 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 = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

from collections import deque

h, w = LI()
si, sj, gi, gj = LI1()
ss = [SI() for _ in range(h)]

mxs = [1]*w
d0 = [[inf]*h for _ in range(w)]
dd = [[inf]*2 for _ in range(h*w)]

q = deque()
for j in range(w):
    q.append((0, j, 0))
    d0[j][0] = 0
while q:
    i, j, f = q.popleft()
    if i == 0:
        d = d0[j][f]

        ni = min(1+f//2, h-1)
        for nj in [j-1, j+1]:
            if nj >= w or nj < 0: continue
            if d < dd[ni*w+nj][1]:
                dd[ni*w+nj][1] = d
                q.appendleft((ni, nj, 1))

        ni = min(1+f, h-1)
        for nj in [j-1, j+1]:
            if nj >= w or nj < 0: continue
            if d+1 < dd[ni*w+nj][1]:
                dd[ni*w+nj][1] = d+1
                q.append((ni, nj, 1))

    else:
        d = dd[i*w+j][f]
        if f:
            if ss[i][j] == "." and d < dd[i*w+j][0]:
                dd[i*w+j][0] = d
                q.appendleft((i, j, 0))
            if i > 1 and d < dd[(i-1)*w+j][1]:
                dd[(i-1)*w+j][1] = d
                q.appendleft((i-1, j, 1))
        else:
            ni = i+1
            if ni < h:
                for nj in [j-1, j+1]:
                    if nj < 0 or nj >= w: continue
                    if ss[ni][nj] == "." and d < dd[ni*w+nj][0]:
                        dd[ni*w+nj][0] = d
                        q.appendleft((ni, nj, 0))

            for nj in [j-1, j+1]:
                if nj < 0 or nj >= w: continue
                if d < d0[nj][i]:
                    d0[nj][i] = d
                    q.appendleft((0, nj, i))
# p2D(d0)
# p2D(dd)

ans = dd[gi*w+gj][0]
if ans == inf: ans = -1

print(ans)
0