結果

問題 No.157 2つの空洞
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-17 09:07:29
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 11,580 KB
実行使用メモリ 15,568 KB
最終ジャッジ日時 2023-08-25 02:48:24
合計ジャッジ時間 3,377 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,276 KB
testcase_01 AC 76 ms
15,152 KB
testcase_02 AC 79 ms
15,256 KB
testcase_03 AC 79 ms
15,072 KB
testcase_04 AC 81 ms
15,216 KB
testcase_05 AC 81 ms
15,280 KB
testcase_06 AC 81 ms
15,124 KB
testcase_07 AC 82 ms
15,152 KB
testcase_08 AC 80 ms
15,284 KB
testcase_09 AC 80 ms
15,160 KB
testcase_10 AC 80 ms
15,076 KB
testcase_11 AC 81 ms
15,116 KB
testcase_12 AC 79 ms
15,160 KB
testcase_13 AC 80 ms
15,124 KB
testcase_14 AC 83 ms
15,336 KB
testcase_15 AC 82 ms
15,120 KB
testcase_16 AC 83 ms
15,124 KB
testcase_17 AC 84 ms
15,568 KB
testcase_18 AC 82 ms
15,120 KB
testcase_19 AC 80 ms
15,116 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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