#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef pair P; typedef long double ld; int main(){ int h, w; cin >> h >> w; vector a(h); rep(y, h) cin >> a[y]; bool simple = true; rep(y, h) rep(x, w) if(a[y][x] == '.') simple = false; int m = min(h, w); if(simple){ cout << m; return 0; } vector> imos(h + 1, vector(w + 1)); rep(y, h) rep(x, w){ if(a[y][x] == '#') imos[y + 1][x + 1]++; } rep(y, h + 1) rep(x, w){ imos[y][x + 1] += imos[y][x]; } rep(y, h) rep(x, w + 1){ imos[y + 1][x] += imos[y][x]; } /* rep(y, h + 1){ rep(x, w + 1) cout << imos[y][x]<< ' '; cout << "\n"; } */ int left = 1, right = m; while(right - left > 1){ int mid = (right + left) / 2; int mid2 = mid * mid; vector>> event(h + 1); rep(y, h - mid + 1) rep(x, w - mid + 1){ if(imos[y + mid][x + mid] - imos[y + mid][x] - imos[y][x + mid] + imos[y][x] == mid2) event[y].emplace_back(x, 1), event[y + mid].emplace_back(x, -1); } vector base(w + 1); vector> b(h, vector(w)); rep(y, h){ for(auto [x, c] : event[y]){ base[x] += c; base[x + mid] -= c; } vector res(w + 1); res[0] = base[0]; rep(x, w) res[x + 1] = res[x] + base[x + 1]; rep(x, w) if(res[x] > 0) b[y][x] = true; } /* cout << mid << "\n"; rep(y, h){ rep(x, w) cout << (b[y][x] ? 1 : 0 )<< ' '; cout << "\n"; } */ bool success = true; rep(y, h) rep(x, w){ if(a[y][x] == '#' and b[y][x] == false) success = false; if(a[y][x] == '.' and b[y][x] == true) success = false; } if(success) left = mid; else right = mid; } cout << left; return 0; }