# yukicoder My Practice # author: Leonardone @ NEETSDKASU ############################################################ def gs() gets.chomp end def gi() gets.to_i end def gf() gets.to_f end def gss() gs.split end def gis() gss.map(&:to_i) end def gfs() gss.map(&:to_f) end def nmapf(n,f) n.times.map{ __send__ f } end def ngs(n) nmapf n,:gs end def ngi(n) nmapf n,:gi end def ngss(n) nmapf n,:gss end def ngis(n) nmapf n,:gis end def arr2d(h,w,v=0) h.times.map{[v] * w} end def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end def nsum(n) n * (n + 1) / 2 end def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end MV4 = [[0, 1], [1, 0], [0, -1], [-1, 0]] MV8 = MV4 + [[1, 1], [-1, -1], [1, -1], [-1, 1]] ############################################################ H, W = gis m = ['.' * W] + ngs(H).map{|r| '.' + r + '.' } + ['.' * W] f = '.' g = ',' d = 0 loop do c = 0 H.times do |y| W.times do |x| next if m[y][x] != f m[y][x] = '_' MV8.each do |dy, dx| ey = y + dy ex = x + dx next if !(0...H).include? ey next if !(0...W).include? ex next if m[ey][ex] != '#' m[ey][ex] = g c += 1 end end end f, g = g, f if c == 0 break else d += 1 end end puts d