// yukicoder: No.707 書道 // 2019.6.25 bal4u #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void ins(char *s) // 文字列の入力 スペース以下の文字で入力終了 { int c; while (1) { if ((c = gc()) < '0') break; *s++ = c & 1; } } int H, W; char map[55][55]; double ans; void calc(int r0, int c0) { int r, c; double s = 0; for (r = 1; r <= H; r++) for (c = 1; c <= W; c++) if (map[r][c]) { s += hypot(r-r0, c-c0); if (s > ans) return; } ans = s; } int main() { int r, c; H = in(), W = in(); for (r = 1; r <= H; r++) ins(map[r]+1); ans = 1.0e20; r = 0; for (c = 1; c <= W; c++) calc(r, c); r = H+1; for (c = 1; c <= W; c++) calc(r, c); c = 0; for (r = 1; r <= H; r++) calc(r, c); c = W+1; for (r = 1; r <= H; r++) calc(r, c); printf("%.12lf\n", ans); return 0; }