#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector s(h); rep(i, h) cin >> s[i]; constexpr int INF = 1001001001; VVI a(h, VI(w, INF)); rep(_, 4) { VVI dp(h, VI(w)); rep(i, h - 1) rep(j, w - 1) { if (s[i][j] == '#') { chmax(dp[i][j], 1); if (s[i+1][j+1] == '#') dp[i+1][j+1] = dp[i][j] + 1; if (dp[i][j] == 1) dp[i][j] = 0; } } rep(i, h) rep(j, w) chmin(a[i][j], dp[i][j]); VVI na(w, VI(h)); vector ns(w, string(h, '.')); rep(i, h) rep(j, w) { int ni = j, nj = h - 1 - i; na[ni][nj] = a[i][j]; ns[ni][nj] = s[i][j]; } swap(h, w); swap(a, na); swap(s, ns); } vector t(h, string(w, '.')); rep(_, 4) { VVI dp(h, VI(w)); rep(i, h) rep(j, w) { chmax(dp[i][j], a[i][j]); if (dp[i][j]) { t[i][j] = '#'; if (i + 1 < h && j + 1 < w) chmax(dp[i+1][j+1], dp[i][j] - 1); } } VVI na(w, VI(h)); vector ns(w, string(h, '.')), nt(w, string(h, '.')); rep(i, h) rep(j, w) { int ni = j, nj = h - 1 - i; na[ni][nj] = a[i][j]; ns[ni][nj] = s[i][j]; nt[ni][nj] = t[i][j]; } swap(h, w); swap(a, na); swap(s, ns); swap(t, nt); } cout << (s == t ? "Yes\n" : "No\n"); }