結果

問題 No.2096 Rage With Our Friends
ユーザー tamatotamato
提出日時 2022-10-07 22:24:05
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,939 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 566,840 KB
最終ジャッジ日時 2023-09-03 13:26:11
合計ジャッジ時間 9,206 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 91 ms
71,540 KB
testcase_02 AC 91 ms
71,404 KB
testcase_03 AC 89 ms
71,728 KB
testcase_04 AC 91 ms
71,784 KB
testcase_05 AC 90 ms
71,716 KB
testcase_06 AC 89 ms
71,448 KB
testcase_07 AC 89 ms
71,664 KB
testcase_08 AC 100 ms
76,404 KB
testcase_09 AC 94 ms
76,380 KB
testcase_10 AC 101 ms
76,472 KB
testcase_11 AC 321 ms
117,720 KB
testcase_12 TLE -
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 #

mod = 998244353


def main():
    import sys
    from bisect import bisect_left
    from collections import deque
    input = sys.stdin.readline

    H, W = map(int, input().split())
    sh, sw, gh, gw = map(int, input().split())
    gh -= 1
    gw -= 1
    G = []
    for _ in range(H):
        G.append(input().rstrip('\n'))

    R = []
    for w in range(W):
        col = []
        for h in range(H):
            if G[h][w] == ".":
                col.append(h)
        R.append(col)

    que = deque()
    seen = [[-1] * W for _ in range(H)]
    for w in range(W):
        que.append((0, 0, w))
    while que:
        x, h, w = que.popleft()
        if seen[h][w] != -1 and seen[h][w] <= x:
            continue
        seen[h][w] = x
        #print(x, h, w)

        # normal jump
        if w - 1 >= 0:
            j = bisect_left(R[w - 1], h+2) - 1
            h_back = R[w - 1][j]
            if seen[h_back][w - 1] == -1 or seen[h_back][w - 1] > x:
                #seen[h_back][w - 1] = x
                que.appendleft((x, h_back, w - 1))
        if w + 1 < W:
            j = bisect_left(R[w + 1], h+2) - 1
            h_back = R[w + 1][j]
            if seen[h_back][w + 1] == -1 or seen[h_back][w + 1] > x:
                #seen[h_back][w + 1] = x
                que.appendleft((x, h_back, w + 1))
        if w - 2 >= 0:
            j = bisect_left(R[w - 1], h+2) - 1
            h_back = R[w - 1][j]
            h_new = h_back + max(0, h - h_back) // 2 + 1
            jj = bisect_left(R[w - 2], h_new + 1) - 1
            hh = R[w - 2][jj]
            if seen[hh][w - 2] == -1 or seen[hh][w - 2] > x:
                #seen[hh][w - 2] = x
                que.appendleft((x, hh, w - 2))
        if w + 2 < W:
            j = bisect_left(R[w + 1], h + 2) - 1
            h_back = R[w + 1][j]
            h_new = h_back + max(0, h - h_back) // 2 + 1
            jj = bisect_left(R[w + 2], h_new + 1) - 1
            hh = R[w + 2][jj]
            if seen[hh][w + 2] == -1 or seen[hh][w + 2] > x:
                #seen[hh][w + 2] = x
                que.appendleft((x, hh, w + 2))

        # super jump
        if w - 2 >= 0:
            h_new = h + 1
            jj = bisect_left(R[w - 2], h_new + 1) - 1
            hh = R[w - 2][jj]
            if seen[hh][w - 2] == -1:
                #seen[hh][w - 2] = x + 1
                que.append((x + 1, hh, w - 2))
        if w + 2 < W:
            h_new = h + 1
            jj = bisect_left(R[w + 2], h_new + 1) - 1
            hh = R[w + 2][jj]
            if seen[hh][w + 2] == -1:
                #seen[hh][w + 2] = x + 1
                que.append((x + 1, hh, w + 2))
        h_new = h + 1
        jj = bisect_left(R[w], h_new + 1) - 1
        hh = R[w][jj]
        if seen[hh][w] == -1:
            #seen[hh][w] = x + 1
            que.append((x + 1, hh, w))

    print(seen[gh][gw])
    #for h in range(H):
    #    print(*seen[h])


if __name__ == '__main__':
    main()
0