結果
問題 | No.157 2つの空洞 |
ユーザー | urutom |
提出日時 | 2017-04-18 19:37:37 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 89 ms / 2,000 ms |
コード長 | 708 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 11,380 KB |
実行使用メモリ | 15,364 KB |
最終ジャッジ日時 | 2023-09-26 13:25:04 |
合計ジャッジ時間 | 3,023 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
15,040 KB |
testcase_01 | AC | 83 ms
15,144 KB |
testcase_02 | AC | 83 ms
15,292 KB |
testcase_03 | AC | 85 ms
15,268 KB |
testcase_04 | AC | 89 ms
15,024 KB |
testcase_05 | AC | 84 ms
15,144 KB |
testcase_06 | AC | 85 ms
15,156 KB |
testcase_07 | AC | 83 ms
15,320 KB |
testcase_08 | AC | 83 ms
15,140 KB |
testcase_09 | AC | 82 ms
15,140 KB |
testcase_10 | AC | 83 ms
15,124 KB |
testcase_11 | AC | 83 ms
15,036 KB |
testcase_12 | AC | 84 ms
15,144 KB |
testcase_13 | AC | 88 ms
15,256 KB |
testcase_14 | AC | 87 ms
15,244 KB |
testcase_15 | AC | 86 ms
15,348 KB |
testcase_16 | AC | 86 ms
15,140 KB |
testcase_17 | AC | 85 ms
15,364 KB |
testcase_18 | AC | 85 ms
15,264 KB |
testcase_19 | AC | 84 ms
15,084 KB |
コンパイルメッセージ
Syntax OK
ソースコード
def color(s,c,h,w) def dfs(s,c,x,y) s[x][y]=c [[1,0],[0,1],[-1,0],[0,-1]].each{|dx,dy| nx=x+dx ny=y+dy dfs(s,c,nx,ny) if s[nx][ny]==?. } end h.times{|i|w.times{|j| if s[i][j]==?. dfs(s,c,i,j) return true end }} false end def dist(p1,p2) (p1[0]-p2[0]).abs+(p1[1]-p2[1]).abs-1 end def min_dist(pts1,pts2) ret=1<<30 pts1.each{|p1|pts2.each{|p2| d=dist(p1,p2) ret=d if d<ret }} ret end w,h=gets.split.map(&:to_i) space=h.times.map{gets.chomp.chars.to_a} color(space,?1,h,w) color(space,?2,h,w) pts1=[] pts2=[] space.each_with_index{|r,x|r.each_with_index{|c,y| if c==?1 pts1<<[x,y] elsif c==?2 pts2<<[x,y] end }} p min_dist(pts1,pts2) #puts space.map(&:join)