#include using namespace std; #if __has_include() #include using namespace atcoder; templateistream &operator>>(istream &is,static_modint &a){long long b;is>>b;a=b;return is;} istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;} #endif using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} templateistream &operator>>(istream &is,pair&p){is>>p.first>>p.second;return is;} templateistream &operator>>(istream &is,vector &a){for(auto &i:a)is>>i;return is;} templatevoid operator++(pair&a,int n){a.first++,a.second++;} templatevoid operator--(pair&a,int n){a.first--,a.second--;} templatevoid operator++(vector&a,int n){for(auto &i:a)i++;} templatevoid operator--(vector&a,int n){for(auto &i:a)i--;} #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcount(x) ll myceil(ll a,ll b){return (a+b-1)/b;} template auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id(d,init)); else return init; } #ifdef LOCAL #include "debug.h" #else #define debug(...) static_cast(0) templateostream &operator<<(ostream &os,const pair&p){os<>testcase; for(int i=0;i struct BinaryIndexedTree2D { int H, W; vector> bit; BinaryIndexedTree2D(int _H, int _W) : H(_H + 1), W(_W + 1) { bit.resize(H + 3, vector(W + 3, 0)); } // 関数の入力のindexは0-originを想定 // (x,y)にwを足す // 範囲外の時は足さない void add(int x, int y, T w) { if (x < 0 || x >= H || y < 0 || y >= W) return; for (int a = (++y, ++x); a <= H; a += a & -a) { for (int b = y; b <= W; b += b & -b) { bit[a][b] += w; } } } // imos法で[(x1,y1) , (x2,y2)]にwを足す void imos(int x1, int y1, int x2, int y2, T w) { add(x1, y1, w); add(x1, y2 + 1, -w); add(x2 + 1, y1, -w); add(x2 + 1, y2 + 1, w); } // [(0,0) , (x,y)]の和 閉区間に注意! // x,y<0の時は0 x>=H y>=Wのときはx=H-1,y=W-1とみなす // ( imos法の時は (x,y)の値を返す ) T sum(int x, int y) { if (x < 0 || y < 0) return 0; if (x >= H) x = H - 1; if (y >= W) y = W - 1; T ret = 0; for (int a = (++y, ++x); a > 0; a -= a & -a) { for (int b = y; b > 0; b -= b & -b) { ret += bit[a][b]; } } return ret; } // [(x1,y1) , (x2,y2)] の和 // x1 > x2, y1 > y2の時はswap T sum(int x1, int y1, int x2, int y2) { if (x1 > x2 || y1 > y2) return T(0); return sum(x2, y2) - sum(x2, y1 - 1) - sum(x1 - 1, y2) + sum(x1 - 1, y1 - 1); } }; /* * @brief 二次元Binary Indexed Tree */ vector>sum; int get(int a,int b,int c,int d){ int ret=sum[c][d]; if(a)ret-=sum[a-1][d]; if(b)ret-=sum[c][b-1]; if(a&&b)ret+=sum[a-1][b-1]; return ret; } void SOLVE(){ int h,w; cin>>h>>w; vectors(h); cin>>s; sum.resize(h,vector(w,0)); rep(i,h)rep(j,w){ sum[i][j]=s[i][j]=='.'; if(i)sum[i][j]+=sum[i-1][j]; if(j)sum[i][j]+=sum[i][j-1]; if(i&&j)sum[i][j]-=sum[i-1][j-1]; } int ok=1,ng=min(h,w)+1; while(ng-ok>1){ int mid=(ok+ng)/2; BinaryIndexedTree2DBIT(h,w); vector>hidariue(h,vector(w,false)); vector>okeru(h,vector(w,false)); rep(i,h)rep(j,w)if(s[i][j]=='#'){ if(i+mid<=h&&j+mid<=w){ if(get(i,j,i+mid-1,j+mid-1)==0)hidariue[i][j]=okeru[i][j]=true,BIT.add(i,j,1); } if(BIT.sum(max(0,i-mid+1),max(0,j-mid+1),i,j)!=0)okeru[i][j]=true; } bool ok2=true; rep(i,h)rep(j,w)if(s[i][j]=='#'&&!okeru[i][j])ok2=false; debug(okeru,hidariue); (ok2?ok:ng)=mid; } cout<