結果

問題 No.157 2つの空洞
ユーザー mlihua09mlihua09
提出日時 2020-09-03 02:32:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,400 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 131,584 KB
最終ジャッジ日時 2024-05-01 23:53:05
合計ジャッジ時間 4,150 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
16,384 KB
testcase_01 AC 35 ms
10,880 KB
testcase_02 AC 38 ms
10,752 KB
testcase_03 AC 37 ms
10,880 KB
testcase_04 AC 34 ms
10,752 KB
testcase_05 AC 36 ms
10,880 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #


W, H = map(int, input().split())
C = [[0 if i == '#' else 1 for i in input()] for j in range(H)]
from collections import deque
que = deque([])

for i in range(H):
    for j in range(W):
        if C[i][j]:
            x = deque([i, j])
            C[i][j] = 0
            while x:
                q1, q2 = x.popleft(), x.popleft()
                if q1 > 0 and C[q1 - 1][q2]:
                    C[q1 - 1][q2] = 0
                    x.append(q1 - 1)
                    x.append(q2)
                if q2 > 0 and C[q1][q2 - 1]:
                    C[q1][q2 - 1] = 0
                    x.append(q1)
                    x.append(q2 - 1)
                if q1 < H - 1 and C[q1 + 1][q2]:
                    C[q1 + 1][q2] = 0
                    x.append(q1 + 1)
                    x.append(q2)
                if q2 < W - 1 and C[q1][q2 + 1]:
                    C[q1][q2 + 1] = 0
                    x.append(q1)
                    x.append(q2 + 1)
                que.extend([q1, q2, 0])
            break
    if que:
        break
while que:
    q1, q2, q3 = que.popleft(), que.popleft(), que.popleft()
    
    if C[q1][q2]:
        print(q3 - 1)
        break
    if q1 > 0:
        que.extend([q1 - 1, q2, q3 + 1])
    if q2 > 0:
        que.extend([q1, q2 - 1, q3 + 1])
    if q1 < H - 1:
        que.extend([q1 + 1, q2, q3 + 1])
    if q2 < W - 1:
        que.extend([q1, q2 + 1, q3 + 1])
0