結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
tnodino
|
| 提出日時 | 2022-06-18 14:34:36 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 858 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-10-10 03:31:03 |
| 合計ジャッジ時間 | 1,870 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
from collections import deque
def bfs():
for i in range(H):
for j in range(W):
if C[i][j] == '.':
C[i][j] = '#'
Queue = deque()
Queue.append((i, j))
s = [(i, j)]
while Queue:
x,y = Queue.popleft()
for i in range(4):
nx,ny = x+dx[i],y+dy[i]
if C[nx][ny] == '.':
C[nx][ny] = '#'
Queue.append((nx, ny))
s.append((nx, ny))
return s
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
W,H = map(int,input().split())
C = [list(input()) for _ in range(H)]
s = bfs()
t = bfs()
ans = 1<<16
for sx,sy in s:
for tx,ty in t:
ans = min(ans, abs(sx-tx) + abs(sy-ty) - 1)
print(ans)
tnodino