結果

問題 No.157 2つの空洞
ユーザー mlihua09mlihua09
提出日時 2020-09-03 02:32:15
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,400 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 568,724 KB
最終ジャッジ日時 2024-05-01 23:52:10
合計ジャッジ時間 5,378 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
61,268 KB
testcase_01 AC 45 ms
54,212 KB
testcase_02 AC 50 ms
59,088 KB
testcase_03 AC 50 ms
61,092 KB
testcase_04 AC 50 ms
61,636 KB
testcase_05 AC 50 ms
59,944 KB
testcase_06 MLE -
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