#include using namespace std; using ll = long long; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b void vprint(T &V){ for(auto v : V){ cout << v << " "; } cout << endl; } struct Point{ ll x; ll y; Point(ll x, ll y): x(x), y(y) {} Point(){} bool operator<(const Point &another) const { if(x == another.x){ return y < another.y; }else{ return x < another.x; } } }; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; vector S; ll W, H; void bfs(ll x, ll y, char c){ queue que; que.push(Point(x, y)); S[y][x] = c; while(!que.empty()){ auto p = que.front(); que.pop(); FOR(i, 0, 4){ ll tx = p.x + dx[i]; ll ty = p.y + dy[i]; if(0<=tx && tx> W >> H; S.resize(H); FOR(i, 0, H){ cin >> S[i]; } // 空洞を見つけてRに塗る FOR(y, 0, H){ FOR(x, 0, W){ if(S[y][x]=='.'){ bfs(x, y, 'R'); goto HERE; } } } HERE: // 空洞を見つけてGに塗る FOR(y, 0, H){ FOR(x, 0, W){ if(S[y][x]=='.'){ bfs(x, y, 'G'); goto THERE; } } } THERE: set se_R; set se_G; // Rに隣接する壁をse_Rに入れる // Gも同様 // それは掘る始点となる FOR(y, 0, H){ FOR(x, 0, W){ FOR(i, 0, 4){ ll tx = x + dx[i]; ll ty = y + dy[i]; if(0<=tx && tx