結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-12 00:44:37 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 818 bytes |
| コンパイル時間 | 380 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 172,288 KB |
| 最終ジャッジ日時 | 2024-11-16 04:29:17 |
| 合計ジャッジ時間 | 4,493 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 TLE * 1 |
ソースコード
from collections import deque
W, H = map(int, input().split())
C = [list(input()) for _ in range(H)]
routes = []
for h in range(H-1):
for w in range(W-1):
if C[h][w] == '.':
r = []
q = deque()
q.append((h, w))
while q:
y0, x0 = q.popleft()
C[y0][x0] = '*' #done
r.append((y0, x0))
for dy, dx in ((-1, 0), (0, 1), (1, 0), (0, -1)):
y1, x1 = y0 + dy, x0 + dx
if 0 <= y1 < H and 0 <= x1 < W and C[y1][x1] == '.':
q.append((y1, x1))
routes.append(r)
ans = H * W
for p0 in routes[0]:
for p1 in routes[1]:
d = abs(p0[0] - p1[0]) + abs(p0[1] - p1[1])
if d - 1 < ans:
ans = d - 1
print(ans)