結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,352 KB
testcase_01 AC 40 ms
51,968 KB
testcase_02 AC 48 ms
59,648 KB
testcase_03 AC 83 ms
72,448 KB
testcase_04 AC 93 ms
76,672 KB
testcase_05 AC 90 ms
74,496 KB
testcase_06 AC 88 ms
74,496 KB
testcase_07 AC 90 ms
74,496 KB
testcase_08 AC 110 ms
76,416 KB
testcase_09 AC 68 ms
66,944 KB
testcase_10 AC 62 ms
64,768 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 49 ms
59,264 KB
testcase_20 WA -
testcase_21 AC 61 ms
63,872 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 98 ms
76,416 KB
testcase_26 AC 60 ms
63,488 KB
testcase_27 AC 55 ms
60,672 KB
testcase_28 AC 65 ms
66,176 KB
testcase_29 WA -
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 abs(i-ni)+abs(j-nj) <= 3 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) <= 3 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