#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> h >> w; vector s(h); vector> sum(h+1,vector(w+1,0)); rep(i,h){ cin >> s[i]; rep(j,w){ sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (s[i][j]=='#'); } } int ok = 1, ng = min(h,w)+1; while(ng-ok>1){ int md = (ok+ng)/2; vector> imos(h+1,vector(w+1,0)); for(int i=0;i<=h-md;i++)for(int j=0;j<=w-md;j++){ if(sum[i+md][j+md]-sum[i][j+md]-sum[i+md][j]+sum[i][j]==md*md){ imos[i][j]++; imos[i][j+md]--; imos[i+md][j]--; imos[i+md][j+md]++; } } rep(i,h+1)rep(j,w) imos[i][j+1] += imos[i][j]; rep(i,h)rep(j,w+1) imos[i+1][j] += imos[i][j]; bool f = true; rep(i,h)rep(j,w){ if((s[i][j]=='#')!=(imos[i][j]!=0)) f = false, i = h, j = w; } if(f) ok = md; else ng = md; } cout << ok << '\n'; return 0; }