#include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for(int i=0;i void print(const T &value) { std::cout << value << std::endl; } void yesno(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; } void YesNo(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; } void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; } typedef long long ll; typedef unsigned long ul; typedef long double ld; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll INF = 10000000; ll mod = 1000000007;//10^9+7 //int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; //int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1}; using Graph = vector>;//隣接リスト:G[i]にはiと隣接する頂点が入るよ。 using P = pair;//BFSで利用。queueに入れる。 using PP = pair; //dijkstraで利用,priority_queueに入れる。 using p_queue = priority_queue, greater()>; //struct edge{int to, cost}; //番号ズレ注意!! int main() { int H, W; cin >> H >> W; string S[H]; vector

black; REP(i, H) { cin >> S[i]; REP(j, W) { if (S[i][j] == '#') { black.emplace_back(i, j); } } } bool two = false; int N = black.size(); REP_1(i, N - 1) {//black[0]がblack[i]に映るような平行移動を考える。 int color[H][W];//color[i][j]:=-1なら未確定,0ならred,1ならblue; REP(k, H) { REP(j, W) { color[k][j] = -1; }} color[black[0].first][black[0].second] = color[black[i].first][black[i].second] = 1; int dx = black[i].first - black[0].first; int dy = black[i].second - black[0].second; bool can = true; int j = 1; while (j < N) { if (color[black[j].first][black[j].second] != -1) { j++;continue; } color[black[j].first][black[j].second] = 0; int nx = black[j].first + dx; int ny = black[j].second + dy; if (nx < 0 || nx >= H || ny < 0 || ny >= W) { can = false; break; } if (S[nx][ny] == '.') { can = false; break; } if (color[nx][ny] == 0) { can = false; break; } color[nx][ny] = 1; j++; } if (can) { two = true; break; } else { continue; } } YESNO(two); }