#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include //#include "util.h" using namespace std; typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; template ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; } template ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; } template ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; } cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; } template ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; } #define PI 3.14159265358979323846 #define EPS 1e-6 #define MIN(a,b) ((a)<(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b)) #define all(x) (x).begin(), (x).end() bool tr(vector S, int w, int h, int b) { int H = S.size(); int W = S[0].size(); for (int y = (h < 0 ? -h : 0); y < (h < 0 ? H : H - h); y++) { for (int x = (w < 0 ? -w : 0); x < (w < 0 ? W : W - w); x++) { if (S[y][x] == '.') continue; if (S[y + h][x + w] == '.') return false; S[y][x] = S[y + h][x + w] = '.'; b -= 2; if (b == 0) return true; } } return false; } int yuki0179() { int H, W, b; cin >> H >> W; vector S(H); for (int i = 0; i < H; i++) cin >> S[i]; //黒マスの個数 b = 0; for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { if (S[y][x] == '#') b++; } } //b 奇数なら false if (b % 2) { cout << "NO" << endl; return 0; } //横に w, 縦に h 平行移動して一致するなら true for (int w = - W + 1; w < W; w++) { for (int h = - H + 1; h < H; h++) { if (w == 0 && h == 0) continue; if (tr(S, w, h, b)) { cout << "YES" << endl; return 0; } } } cout << "NO" << endl; return 0; } int main() { //clock_t start, end; //start = clock(); yuki0179(); //end = clock(); //printf("%d msec.\n", end - start); return 0; }