結果
問題 |
No.157 2つの空洞
|
ユーザー |
|
提出日時 | 2020-03-12 00:49:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 968 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-11-16 04:29:36 |
合計ジャッジ時間 | 1,482 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
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)) C[h][w] = '*' #done r.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)) C[y1][x1] = '*' #done r.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)