結果

問題 No.2412 YOU Grow Bigger!
ユーザー AngrySadEightAngrySadEight
提出日時 2023-07-20 00:21:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,979 ms / 6,000 ms
コード長 2,625 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 123,736 KB
最終ジャッジ日時 2024-05-01 06:33:40
合計ジャッジ時間 15,911 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,480 KB
testcase_01 AC 42 ms
55,316 KB
testcase_02 AC 49 ms
63,796 KB
testcase_03 AC 1,786 ms
123,736 KB
testcase_04 AC 1,821 ms
123,220 KB
testcase_05 AC 1,361 ms
106,144 KB
testcase_06 AC 1,979 ms
114,752 KB
testcase_07 AC 1,781 ms
123,440 KB
testcase_08 AC 1,753 ms
115,120 KB
testcase_09 AC 58 ms
69,152 KB
testcase_10 AC 131 ms
77,096 KB
testcase_11 AC 56 ms
67,272 KB
testcase_12 AC 45 ms
61,148 KB
testcase_13 AC 158 ms
77,472 KB
testcase_14 AC 90 ms
76,724 KB
testcase_15 AC 55 ms
66,252 KB
testcase_16 AC 59 ms
68,376 KB
testcase_17 AC 61 ms
69,696 KB
testcase_18 AC 332 ms
80,712 KB
testcase_19 AC 54 ms
65,636 KB
testcase_20 AC 57 ms
66,980 KB
testcase_21 AC 134 ms
76,708 KB
testcase_22 AC 152 ms
77,516 KB
testcase_23 AC 558 ms
84,200 KB
testcase_24 AC 907 ms
91,552 KB
testcase_25 AC 471 ms
83,332 KB
testcase_26 AC 123 ms
77,068 KB
testcase_27 AC 101 ms
76,824 KB
testcase_28 AC 206 ms
78,284 KB
testcase_29 AC 55 ms
67,308 KB
testcase_30 AC 46 ms
60,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


def main():
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        S.append(input())

    que = deque([(0, 0)])
    isvisited = [[False for _ in range(W - 2)] for _ in range(H - 2)]
    isvisited[0][0] = True
    dx = [1, 1, 0, -1, -1, -1, 0, 1]
    dy = [0, 1, 1, 1, 0, -1, -1, -1]

    pos = [[True for _ in range(W - 2)] for _ in range(H - 2)]
    for i in range(H - 2):
        for j in range(W - 2):
            for k in range(3):
                for l in range(3):
                    if S[i + k][j + l] == "#":
                        pos[i][j] = False

    while que:
        p = que.popleft()
        for i in range(8):
            if 0 <= p[0] + dx[i] < H - 2 and 0 <= p[1] + dy[i] < W - 2:
                if isvisited[p[0] + dx[i]][p[1] + dy[i]]:
                    continue
                if pos[p[0] + dx[i]][p[1] + dy[i]]:
                    isvisited[p[0] + dx[i]][p[1] + dy[i]] = True
                    que.append((p[0] + dx[i], p[1] + dy[i]))

    if not isvisited[H - 3][W - 3]:
        print(0)
        return

    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                continue
            if 0 <= i <= 2 and 0 <= j <= 2:
                continue
            if H - 3 <= i < H and W - 3 <= j < W:
                continue
            S[i] = S[i][:j] + "#" + S[i][j + 1 :]
            que.append((0, 0))
            for k in range(H - 2):
                for l in range(W - 2):
                    isvisited[k][l] = False

            isvisited[0][0] = True
            for k in range(H - 2):
                for l in range(W - 2):
                    pos[k][l] = True
            for k in range(H - 2):
                for l in range(W - 2):
                    for m in range(3):
                        for n in range(3):
                            if S[k + m][l + n] == "#":
                                pos[k][l] = False

            while que:
                p = que.popleft()
                for k in range(8):
                    if 0 <= p[0] + dx[k] < H - 2 and 0 <= p[1] + dy[k] < W - 2:
                        if isvisited[p[0] + dx[k]][p[1] + dy[k]]:
                            continue
                        if pos[p[0] + dx[k]][p[1] + dy[k]]:
                            isvisited[p[0] + dx[k]][p[1] + dy[k]] = True
                            que.append((p[0] + dx[k], p[1] + dy[k]))

            if not isvisited[H - 3][W - 3]:
                print(1)
                return

            S[i] = S[i][:j] + "." + S[i][j + 1 :]

    print(2)


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