結果

問題 No.2412 YOU Grow Bigger!
ユーザー sotanishysotanishy
提出日時 2023-08-11 23:19:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2024-04-29 14:30:52
合計ジャッジ時間 3,325 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,480 KB
testcase_01 AC 43 ms
52,608 KB
testcase_02 AC 49 ms
59,648 KB
testcase_03 AC 84 ms
72,576 KB
testcase_04 AC 95 ms
76,288 KB
testcase_05 AC 92 ms
74,368 KB
testcase_06 AC 89 ms
74,624 KB
testcase_07 AC 90 ms
74,368 KB
testcase_08 AC 115 ms
76,288 KB
testcase_09 AC 64 ms
63,488 KB
testcase_10 AC 62 ms
64,384 KB
testcase_11 AC 55 ms
60,928 KB
testcase_12 AC 43 ms
52,608 KB
testcase_13 AC 64 ms
64,768 KB
testcase_14 AC 54 ms
61,312 KB
testcase_15 AC 63 ms
64,640 KB
testcase_16 AC 61 ms
63,744 KB
testcase_17 AC 59 ms
62,592 KB
testcase_18 AC 86 ms
73,344 KB
testcase_19 AC 57 ms
61,824 KB
testcase_20 AC 54 ms
60,032 KB
testcase_21 WA -
testcase_22 AC 66 ms
66,304 KB
testcase_23 AC 99 ms
76,160 KB
testcase_24 AC 104 ms
76,416 KB
testcase_25 WA -
testcase_26 AC 64 ms
64,640 KB
testcase_27 AC 56 ms
61,696 KB
testcase_28 AC 72 ms
67,840 KB
testcase_29 AC 56 ms
61,824 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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 (ni, nj) != (i, j) 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 (ni, nj) != (i, j) 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):
        r1 = r2 = 0
        for ni in range(i-3, i+4):
            for nj in range(j-3, j+4):
                if (ni, nj) != (i, j) 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