結果

問題 No.157 2つの空洞
ユーザー horiesiniti
提出日時 2018-03-17 09:07:29
言語 Ruby
(3.4.1)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-12-23 14:52:23
合計ジャッジ時間 2,526 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(x,y,w,h,no)
	dx=[1,0,-1,0]
	dy=[0,1,0,-1]
	$map[y][x]=no.to_s
	$hs[no]<<[y,x]
	4.times{|i|
		x1=x+dx[i]
		y1=y+dy[i]
		if x1<0 || x1>=w || y1<0 || y1>=h || $map[y1][x1]!="."
			next
		end
		f(x1,y1,w,h,no)
	}
end
w,h=gets.split.map{|e| e.to_i}
$map=STDIN.read.split
$hs=[[],[]]
no=0
h.times{|y|
	w.times{|x|
		if $map[y][x]=="."
			f(x,y,w,h,no)
			no+=1
		end
	}
}
ans=10000
$hs[0].each{|e1|
	$hs[1].each{|e2|
		d=(e1[0]-e2[0]).abs+(e1[1]-e2[1]).abs-1
		
		ans=[ans,d].min
	}
}
puts ans
0