#include #include #include #include using namespace std; int main(){ int H, W; cin >> H >> W; string sample[H]; for(int i = 0; i < H; i++){ cin >> sample[i]; } double ans = 1e9; for(int i = 0; i < H; i++){ double this_ans = 0; for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ if(sample[y][x] == '1'){ this_ans += sqrt((x + 1) * (x + 1) + (y - i) * (y - i)); } } } ans = min(ans, this_ans); } for(int i = 0; i < H; i++){ double this_ans = 0; for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ if(sample[y][x] == '1'){ this_ans += sqrt((W - x) * (W - x) + (y - i) * (y - i)); } } } ans = min(ans, this_ans); } for(int i = 0; i < W; i++){ double this_ans = 0; for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ if(sample[y][x] == '1'){ this_ans += sqrt((y + 1) * (y + 1) + (x - i) * (x - i)); } } } ans = min(ans, this_ans); } for(int i = 0; i < W; i++){ double this_ans = 0; for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ if(sample[y][x] == '1'){ this_ans += sqrt((H - y) * (H - y) + (x - i) * (x - i)); } } } ans = min(ans, this_ans); } cout << setprecision(12) << ans << endl; }