結果

問題 No.157 2つの空洞
ユーザー Tawara
提出日時 2015-09-06 01:14:20
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 50 ms
コンパイル使用メモリ 6,940 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-19 04:16:48
合計ジャッジ時間 953 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(hx,hy):
	C[hy][hx] = "#"
	U[UN].add((hx,hy))
	for dx,dy in dxy:
			nx = hx + dx
			ny = hy + dy
			if 0 <= nx < W and 0 <= ny < H and C[ny][nx] == ".":
				dfs(nx,ny)
dxy = ((1,0),(0,1),(-1,0),(0,-1))
W,H = map(int,raw_input().split())
C = [list(raw_input()) for i in range(H)]
U = [set(),set()]
UN = 0
for i in range(H):
	for j in range(W):
		if C[i][j] == ".":
			dfs(j,i)
			UN += 1
print min(abs(x0-x1)+abs(y0-y1) for x0,y0 in U[0] for x1,y1 in U[1])-1
0