using System; using System.Collections.Generic; using System.Linq; namespace _707 { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var h = line[0]; var w = line[1]; var blacks = new List>(); for (int x = 0; x < h; x++) { var row = Console.ReadLine().Select(ch => ch - '0').ToList(); for (int y = 0; y < w; y++) { if (row[y] == 1) { blacks.Add(Tuple.Create(x + 1, y + 1)); } } } var positions = Enumerable.Range(0, h + 2) .SelectMany(x => Enumerable.Range(0, w + 2).Select(y => Tuple.Create(x, y))) .Where(position => position.Item1 == 0 || position.Item2 == h + 1 || position.Item2 == 0 || position.Item2 == w + 1) .ToList(); var answer = positions.Min(position => { return blacks.Sum(black => { var x = Math.Pow((double)(position.Item1 - black.Item1), 2.0); var y = Math.Pow((double)(position.Item2 - black.Item2), 2.0); return Math.Sqrt(x + y); }); }); Console.WriteLine(Math.Round(answer, 8)); } } }