#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 void Sum(vector> &sum){ int h = sum.size()-1,w = sum[0].size()-1; rep(i,h){ rep(j,w+1)sum[i+1][j] += sum[i][j]; } rep(i,h+1){ rep(j,w)sum[i][j+1] += sum[i][j]; } } int main(){ int h,w; cin>>h>>w; vector s(h); rep(i,h)cin>>s[i]; vector sum(h+1,vector(w+1)); rep(i,h){ rep(j,w){ if(s[i][j]=='#')sum[i+1][j+1] = 1; } } Sum(sum); int ok = 1,ng = max(h,w)+1; while(ng-ok>1){ int mid = (ok+ng)/2; vector dp(h+1,vector(w+1)); rep(i,h){ rep(j,w){ if(i+mid>h||j+mid>w)continue; if(sum[i+mid][j+mid] - sum[i+mid][j] - sum[i][j+mid] + sum[i][j] == mid*mid){ dp[i][j] ++; dp[i+mid][j] --; dp[i][j+mid] --; dp[i+mid][j+mid] ++; } } } Sum(dp); bool f =true; rep(i,h){ rep(j,w){ if(s[i][j]=='#'&&dp[i][j]==0){ f = false; } } } if(f)ok = mid; else ng = mid; } cout<