// #pragma GCC optimize("O3,unroll-loops") #include // #include using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif template T &ctmin(T &x){ return x; } template T &ctmin(T &x, const Head &h, const Tail &... t){ return ctmin(x = min(x, h), t...); } template T &ctmax(T &x){ return x; } template T &ctmax(T &x, const Head &h, const Tail &... t){ return ctmax(x = max(x, h), t...); } int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int nr, nc; cin >> nr >> nc; vector a(nr); copy_n(istream_iterator(cin), nr, a.begin()); vector ul(nr, vector(nc, 1)); auto ur = ul; auto dl = ul; auto dr = ul; for(auto x = 0; x < nr; ++ x){ for(auto y = 0; y < nc; ++ y){ if(a[x][y] == '.'){ ul[x][y] = ur[x][y] = 0; continue; } if(x >= 1){ if(y >= 1){ ul[x][y] = ul[x - 1][y - 1] + 1; } if(y + 1 < nc){ ur[x][y] = ur[x - 1][y + 1] + 1; } } } } for(auto x = nr - 1; x >= 0; -- x){ for(auto y = 0; y < nc; ++ y){ if(a[x][y] == '.'){ dl[x][y] = dr[x][y] = 0; continue; } if(x + 1 < nr){ if(y >= 1){ dl[x][y] = dl[x + 1][y - 1] + 1; } if(y + 1 < nc){ dr[x][y] = dr[x + 1][y + 1] + 1; } } } } vector> res_sum(nr, vector(nc)); vector> res_dif(nr, vector(nc)); for(auto x = 1; x < nr - 1; ++ x){ for(auto y = 1; y < nc - 1; ++ y){ int radius = min({ul[x][y], ur[x][y], dl[x][y], dr[x][y]}); if(radius <= 1){ continue; } ++ res_sum[x - radius + 1][y - radius + 1]; if(x + radius < nr && y + radius < nc){ -- res_sum[x + radius][y + radius]; } ++ res_dif[x - radius + 1][y + radius - 1]; if(x + radius < nr && y - radius >= 0){ -- res_dif[x + radius][y - radius]; } } } for(auto x = 0; x < nr - 1; ++ x){ for(auto y = 0; y < nc; ++ y){ if(y + 1 < nc){ res_sum[x + 1][y + 1] += res_sum[x][y]; } if(y - 1 >= 0){ res_dif[x + 1][y - 1] += res_dif[x][y]; } } } for(auto x = 0; x < nr; ++ x){ for(auto y = 0; y < nc; ++ y){ if(!!(res_sum[x][y] + res_dif[x][y]) != (a[x][y] == '#')){ cout << "No\n"; return 0; } } } cout << "Yes\n"; return 0; } /* */