結果

問題 No.2412 YOU Grow Bigger!
ユーザー sotanishysotanishy
提出日時 2023-08-11 23:24:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 6,000 ms
コード長 1,795 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,724 KB
最終ジャッジ日時 2024-05-01 06:37:41
合計ジャッジ時間 3,647 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,772 KB
testcase_01 AC 42 ms
54,720 KB
testcase_02 AC 40 ms
52,948 KB
testcase_03 AC 124 ms
77,560 KB
testcase_04 AC 121 ms
77,216 KB
testcase_05 AC 125 ms
77,596 KB
testcase_06 AC 120 ms
77,500 KB
testcase_07 AC 121 ms
77,484 KB
testcase_08 AC 123 ms
77,596 KB
testcase_09 AC 61 ms
68,736 KB
testcase_10 AC 58 ms
66,536 KB
testcase_11 AC 53 ms
63,716 KB
testcase_12 AC 39 ms
53,328 KB
testcase_13 AC 68 ms
70,716 KB
testcase_14 AC 50 ms
60,940 KB
testcase_15 AC 64 ms
68,004 KB
testcase_16 AC 59 ms
64,964 KB
testcase_17 AC 61 ms
67,096 KB
testcase_18 AC 105 ms
76,684 KB
testcase_19 AC 56 ms
64,860 KB
testcase_20 AC 48 ms
61,348 KB
testcase_21 AC 73 ms
72,252 KB
testcase_22 AC 69 ms
72,104 KB
testcase_23 AC 110 ms
76,548 KB
testcase_24 AC 116 ms
77,724 KB
testcase_25 AC 116 ms
77,516 KB
testcase_26 AC 62 ms
67,376 KB
testcase_27 AC 51 ms
62,132 KB
testcase_28 AC 75 ms
72,200 KB
testcase_29 AC 54 ms
64,096 KB
testcase_30 AC 40 ms
53,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
S = [input().rstrip() for _ in range(H)]

reachable1 = [[0] * W for _ in range(H)]
st = []
for i in range(H):
    for j in range(W):
        if S[i][j] == '#' and (i >= H-3 or j < 3):
            reachable1[i][j] = 1
            st.append((i, j))
while st:
    i, j = st.pop()
    for ni in range(i-3, i+4):
        for nj in range(j-3, j+4):
            if abs(i-ni)+abs(j-nj) <= 5 and 0 <= ni < H and 0 <= nj < W and S[ni][nj] == '#' and not reachable1[ni][nj]:
                reachable1[ni][nj] = 1
                st.append((ni, nj))


reachable2 = [[0] * W for _ in range(H)]
st = []
for i in range(H):
    for j in range(W):
        if S[i][j] == '#' and (i < 3 or j >= W-3):
            reachable2[i][j] = 1
            st.append((i, j))
while st:
    i, j = st.pop()
    for ni in range(i-3, i+4):
        for nj in range(j-3, j+4):
            if abs(i-ni)+abs(j-nj) <= 5 and 0 <= ni < H and 0 <= nj < W and S[ni][nj] == '#' and not reachable2[ni][nj]:
                reachable2[ni][nj] = 1
                st.append((ni, nj))

for i in range(H):
    for j in range(W):
        if reachable1[i][j] and reachable2[i][j]:
            print(0)
            exit()

for i in range(H):
    for j in range(W):
        if (i < 3 and j < 3) or (i >= H-3 and j >= W-3):
            continue
        r1 = r2 = 0
        if i >= H-3 or j < 3:
            r1 = 1
        if i < 3 or j >= W-3:
            r2 = 1
        for ni in range(i-3, i+4):
            for nj in range(j-3, j+4):
                if abs(i-ni)+abs(j-nj) <= 5 and 0 <= ni < H and 0 <= nj < W:
                    r1 |= reachable1[ni][nj]
                    r2 |= reachable2[ni][nj]
        if r1 and r2:
            print(1)
            exit()

print(2)
0