#include #define rep(i, n, s) for(int (i) = 0; (i) < (n); (i) += (s)) using namespace std; int main() { int h, w; int start = -1; int shap = 0; int blue_point = -1; int point_length = 0; cin >> h >> w; vector s(h * w, 0); vector check_s(h * w, 0); vector shap_index; for (int i = 0; i < h * w; ++i) { cin >> s[i]; if (s[i] == '#') { shap++; shap_index.push_back(i); } if (s[i] == '#' && start == -1) { start = i; s[i] = '.'; } // else (s[i] == '#' && blue_point == -1) // blue_point = i; } if (shap % 2 == 1) { cout << "NO" << endl; exit(0); } int count = 0; while(1) { check_s = s; count++; for (int i = 0; i < h * w; ++i) { if (check_s[i] == '#' && blue_point == -1) { blue_point = i; check_s[i] = '.'; } if (check_s[i] == '#') { // 赤 point_length = i - start; check_s[i] = '.'; // 青 if (blue_point + point_length >= h * w) { cout << "NO" << endl; exit(0); } if (check_s[blue_point + point_length] == '#') check_s[blue_point + point_length] = '.'; else { if (i == h * w - 1) break; else { blue_point = shap_index[1 + count]; continue; } } } } cout << "YES" << endl; exit(0); } cout << "NO" << endl; }