結果
問題 |
No.157 2つの空洞
|
ユーザー |
|
提出日時 | 2020-09-03 02:32:37 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,400 bytes |
コンパイル時間 | 81 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 144,768 KB |
最終ジャッジ日時 | 2024-11-22 08:15:24 |
合計ジャッジ時間 | 20,896 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 TLE * 6 |
ソースコード
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])