//#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define int long long #define ln '\n' #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define next asdnext #define prev asdprev #define P(p) cout << (p) << endl; #define S(s) cin << (s); #define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i)) #define rep(i,n) reps(i,0,n) #define repst(i,a,b) rep(i,s,(n)+1) #define rept(i,n) rep(i,(n)+1) #define reprt(i,a,b) for(int (i)=(a); (i)>=(b); --(i)) #define repr(i,n) reprt(i,n,0) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define debug(x) cerr << #x << ": " << x << '\n' #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) #define tmax(x,y,z) max(x,max(y,z)) #define tmin(x,y,z) min(x,min(y,z)) #define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) typedef long double ld; typedef long long ll; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vl; typedef vector vst; typedef vector vb; typedef vector vld; typedef vector vpii; typedef vector vpll; typedef vector > mat; const int MOD = 1e9 + 7; const int INF = 1e9; const ll INFF = 1e18; const double EPS = 1e-9; const double PI = acos(-1.0); /*********TEMPLATE**********/ ld calc(int x1, int y1, int x2, int y2) { //cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) << ln; return sqrtl((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); } int main() { int H, W; char c; string s; int board[50][50]; cin >> H >> W; rep(i,H) { cin >> s; rep(j,W) { c = s[j]; board[i][j] = c - '0'; } } ld min = INF, tmp; // 左側 rep(i,H) { tmp = 0; int x = i; int y = -1; rep(p,H) { rep(q,W) { if (board[p][q]==1) tmp += calc(p, q, x, y); } }//cout << x << ',' << y << ' ' << tmp << ln; if (min > tmp) min = tmp; } // 右側 rep(i,H) { tmp = 0; int x = i; int y = W; rep(p,H) { rep(q,W) { if (board[p][q]==1) tmp += calc(p, q, x, y); } }//cout << x << ',' << y << ' ' << tmp << ln; if (min > tmp) min = tmp; } // 上側 rep(i,W) { tmp = 0; int x = -1; int y = i; rep(p,H) { rep(q,W) { if (board[p][q]==1) tmp += calc(p, q, x, y); } }//cout << x << ',' << y << ' ' << tmp << ln; if (min > tmp) min = tmp; } // 下側 rep(i,W) { tmp = 0; int x = H; int y = i; rep(p,H) { rep(q,W) { if (board[p][q]==1) tmp += calc(p, q, x, y); } }//cout << x << ',' << y << ' ' << tmp << ln; if (min > tmp) min = tmp; } cout << setprecision(100) << min << ln; /* rep(i,H) { rep(j,W) { cout << board[i][j] << ' '; } cout << ln; } */ return 0; }