#include #include #include #include #include #define FOR(i_type, i, i_min, i_max) for(i_type i = (i_min); i < (i_max); ++i) using namespace std; typedef vector> Grid; bool test_trans(vector> grid /*copy*/, long i, long j, size_t blacks) { // 黒いマスを消す FOR (long, ii, 0, grid.size() - i) { FOR(long, jj, j > 0 ? 0 : -j, grid[0].size() - (j > 0 ? j : 0)) { if (grid[ii][jj]) { auto const dest = grid.at(ii + i).at(jj + j); if (dest) { grid[ii+i][jj+j] = 0; blacks-=2; } else { return false; } } } } return blacks == 0; } int main(void) { int H, W; cin >> H >> W; // 入力データを読み込む Grid grid(H, vector(W, false)); size_t blacks = 0; FOR (size_t, i, 0, H) { string line; cin >> line; FOR(size_t, j, 0, W) { if (line[j] == '#') { grid[i][j] = true; blacks++; } } } bool ok = false; if (blacks == 0 or blacks & 1) ok = false; else { // Test all possible translations FOR(size_t, i, 0, H) { FOR (long, j, -W + 1, W) { if ((i != 0 or j != 0) and /* 平行移動していないからスキップ */ (ok |= test_trans(grid, i, j, blacks))) break; } } } cout << (ok ? "YES" : "NO") << endl; return 0; }