#include #include #include #include using namespace std; int main() { int h, w; cin >> h >> w; vector s(h); int blackCount = 0; for (int i = 0; i < h; ++i) { cin >> s[i]; blackCount += count(s[i].begin(), s[i].end(), '#'); } if (blackCount == 0 || blackCount % 2 == 1) { cout << "NO" << endl; return 0; } const int OFFSET_BASE = 50; static bool movable[50][50][100][100]; // [cellX][cellY][offsetX][offsetY] for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { if (s[y][x] == '.') { fill(&movable[x][y][0][0], &movable[x][y][99][99] + 1, false); } else { for (int offsetY = -h; offsetY < h; ++offsetY) { for (int offsetX = -w; offsetX < w; ++offsetX) { movable[x][y][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY] = (0 <= x + offsetX && x + offsetX < w) && (0 <= y + offsetY && y + offsetY < h) && (s[y + offsetY][x + offsetX] == '#'); } } } } } for (int offsetY = -h; offsetY < h; ++offsetY) { for (int offsetX = -w; offsetX < w; ++offsetX) { int movableCount = 0; for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { if (movable[x][y][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY]) { ++movableCount; } } } if (movableCount == blackCount / 2) { bool overlapped = false; for (int y = 0; y < h && !overlapped; ++y) { for (int x = 0; x < w && !overlapped; ++x) { if (movable[x][y][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY] && movable[x + offsetX][y + offsetY][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY]) { overlapped = true; } } } if (!overlapped) { cout << "YES" << endl; return 0; } } } } cout << "NO" << endl; return 0; }