結果
| 問題 | No.157 2つの空洞 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-03 02:32:37 |
| 言語 | Python3 (3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,400 bytes |
| 記録 | |
| コンパイル時間 | 673 ms |
| コンパイル使用メモリ | 15,104 KB |
| 実行使用メモリ | 342,016 KB |
| 最終ジャッジ日時 | 2026-09-28 01:24:00 |
| 合計ジャッジ時間 | 7,074 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 6 TLE * 1 -- * 9 |
ソースコード
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])