#include using namespace std; using ll = long long; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> H >> W; stringstream ss; FOR(i, 0, W+2){ ss << '.'; } string dot = ss.str(); vector S(H+2); FOR(i, 1, H+1){ string s; cin >> s; s = "." + s + "."; S[i] = s; } S[0] = dot; S[H+2-1] = dot; double ans = inf; FOR(i, 0, H+2){ FOR(j, 0, W+2){ if(S[i][j]!='.') continue; double sum = 0; FOR(y, 1, H+1){ FOR(x, 1, W+1){ if(S[y][x]=='1'){ sum += calc_dist(i, j, y, x); } } } chmin(ans, sum); } } cout << setprecision(20); p(ans); return 0; }