#include #include //#define DEBUG 0 int main() { enum class State{ None,Red,Blue,Undefined }; int height, width; std::cin >> height >> width; std::string l; std::getline(std::cin, l); State map[50][50]; int cell_count = 0; for (int y = 0; y < height; y++) { std::string line; std::getline(std::cin, line); for (int x = 0; x < width; x++) { if (line[x] == '.') { map[x][y] = State::None; } else { cell_count++; map[x][y] = State::Undefined; } } } if (cell_count == 0 || cell_count % 2 == 1) { std::cout << "NO" << std::endl; return 0; } bool is_find=false; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (x != 0 || y != 0) { is_find=true; int blue_count = 0; int red_count = 0; State map_copy[50][50]; #ifdef DEBUG std::cout << x << "," << y << std::endl; #endif for (int y1 = 0; y1 < height; y1++) { for (int x1 = 0; x1 < width; x1++) { map_copy[x1][y1] = map[x1][y1]; } } for (int y_add = 0; y_add < height; y_add++) { for (int x_add = 0; x_add < width; x_add++) { if (map_copy[x_add][y_add] == State::None) { }else if (x_add - x < 0 || y_add - y < 0) { blue_count++; map_copy[x_add][y_add] = State::Blue; if (blue_count * 2 > cell_count) { is_find = false; break; } } else if (map_copy[x_add - x][y_add - y] == State::Blue) { red_count++; map_copy[x_add][y_add] = State::Red; } else { blue_count++; map_copy[x_add][y_add] = State::Blue; } #ifdef DEBUG for (int y1 = 0; y1 < height; y1++) { for (int x1 = 0; x1 < width; x1++) { std::cout << (int)map_copy[x1][y1]; } std::cout << std::endl; } std::cout << std::endl; #endif // DEBUG } } #ifdef DEBUG std::cout << cell_count << ":" << red_count << ":" << blue_count << std::endl; #endif // DEBUG if (is_find == true&&blue_count + red_count == cell_count&&red_count==blue_count) { goto loop1_end; } else { is_find = false; } } } } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (x != 0 || y != 0) { is_find = true; int blue_count = 0; int red_count = 0; State map_copy[50][50]; for (int y1 = 0; y1 < height; y1++) { for (int x1 = 0; x1 < width; x1++) { map_copy[x1][y1] = map[x1][y1]; } } #ifdef DEBUG std::cout << x << "," << -y << std::endl; #endif // DEBUG for (int y_add = height-1; y_add > 0; y_add--) { for (int x_add = 0; x_add < width; x_add++) { if (map_copy[x_add][y_add] == State::None) { } else if (x_add - x < 0 || y_add + y > height) { blue_count++; map_copy[x_add][y_add] = State::Blue; if (blue_count * 2 > cell_count) { is_find = false; break; } } else if (map_copy[x_add - x][y_add + y] == State::Blue) { red_count++; map_copy[x_add][y_add] = State::Red; } else { blue_count++; map_copy[x_add][y_add] = State::Blue; } #ifdef DEBUG for (int y1 = 0; y1 < height; y1++) { for (int x1 = 0; x1 < width; x1++) { std::cout<<(int)map_copy[x1][y1]; } std::cout << std::endl; } std::cout << std::endl; #endif // DEBUG } } #ifdef DEBUG std::cout << cell_count << ":" << red_count << ":" << blue_count << std::endl; #endif // DEBUG if (is_find == true && blue_count + red_count == cell_count&&red_count == blue_count) { goto loop1_end; } else { is_find = false; } } } } loop1_end: std::cout << (is_find ? "YES" : "NO") << std::endl; }