#include using namespace std; //重み付きUnion_Find(和) struct Weighted_dsu { public: Weighted_dsu() : _n(0) {} Weighted_dsu(int n) : _n(n), parent_or_size(n, -1),diff_weight(n,0) {} bool merge(int a, int b, long long w) { int x = leader(a), y = leader(b); if(x==y){ if(diff(a,b)==w)return true; return false; } w += diff_weight[a]; w -= diff_weight[b]; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y),w*=-1; parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; diff_weight[y] = w; return true; } long long diff(int x, int y) { leader(x),leader(y); return diff_weight[y] - diff_weight[x]; } bool same(int a, int b) { return leader(a) == leader(b); } int leader(int a) { if (parent_or_size[a] < 0) return a; int r = leader(parent_or_size[a]); diff_weight[a] += diff_weight[parent_or_size[a]]; return parent_or_size[a] = r; } int size(int a) { return -parent_or_size[leader(a)]; } std::vector> groups() { std::vector leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector& v) { return v.empty(); }), result.end()); return result; } private: int _n; std::vector parent_or_size; std::vector diff_weight; }; int main(){ int H, W; cin >> H >> W; vector A(H); for(auto &&s:A)cin >> s; for(int my = 0; my <= 50; my++){ for(int mx = 0; mx <= 50; mx++){ if(my == 0 && mx == 0)continue; bool flag = true; Weighted_dsu uf(H * W); for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ if(A[y][x] == '#' && uf.size(y * W + x) == 1){ if(y + my >= H || x + mx >= W){ flag = false; continue; } if(A[y + my][x + mx] == '#'){ uf.merge(y * W + x, (y + my) * W + x + mx, 1); }else{ flag = false; } } } } if(flag){ cout << "YES" << '\n'; return 0; } } } cout << "NO" << '\n'; }