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]; for(int i=0; i()); } string tmp = Reader.ReadLine(); for(int j=0; ja.Value.Count(b=>b.Value == i) > 0).Select(a=>a.Key).ToArray(); yKeys.ToList().ForEach(a=>{ step[a].Where(b=>b.Value == i).ToList().ForEach(b=>{ for(int j=Math.Max(0, a-1); j<=Math.Min(H-1, a+1); j++) { for(int k=Math.Max(0, b.Key - 1); k<=Math.Min(W-1, b.Key+1); k++) { if((!step[j].ContainsKey(k)) && map[j,k] == '#') { step[j][k] = i+1; } } } }); }); } 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 = @" 8 8 .#..#... .######. #####... #####.#. ######## ######.# #####... ...####. "; 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(); } }