using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int H = inpt[0]; int W = inpt[1]; Dictionary> step = new Dictionary>(); char[,] map = new char[H, W]; Queue q = new Queue(); for(int i=0; i 0) { int[] task = q.Dequeue(); int posY = task[0]; int posX = task[1]; int cnt = task[2]; if(!step.ContainsKey(posY)) { step.Add(posY, new Dictionary()); } if((!step[posY].ContainsKey(posX)) || step[posY][posX] > cnt) { step[posY][posX] = cnt; for(int i = Math.Max(0, posY-1); i<= Math.Min(H-1, posY+1); i++) { for(int j=Math.Max(0, posX - 1); j<= Math.Min(W-1, posX+1); j++) { if(i==posY && j == posX) { continue; } if(map[i,j] == '#' ) { int[] newT = new int[]{i,j, cnt+1}; q.Enqueue(newT); } } } } } int ans = step.Max(a=>a.Value.Max(b=>b.Value)); Console.WriteLine(ans); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }