-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Colour_the_Flag.cpp
More file actions
132 lines (132 loc) · 3.14 KB
/
A_Colour_the_Flag.cpp
File metadata and controls
132 lines (132 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
#define ll long long int
#define pb push_back
#define fo(a,b,c) for(int a=b;a<c;a++)
#define ff(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define YES cout<< 'YES' << endl
#define NO cout<< 'NO' << endl
using namespace std;
const int E = 2e3 + 100;
const int mod = 1e9 + 7;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;cin>>t;
while(t--)
{
ll n,m;cin>>n>>m;
string st;
vector<vector<ll>> arr(n,vector<ll>(m));
queue<pair<ll,ll>> q;
vector<vector<ll>> vis(n,vector<ll>(m,0));
for(ll i=0;i<n;i++){
cin>>st;
for(ll j=0;j<m;j++){
if(st[j]=='.'){
arr[i][j]=0;
}
else if(st[j]=='R'){
arr[i][j]=1;
q.push(make_pair(i,j));
}
else{
arr[i][j]=2;
q.push(make_pair(i,j));
}
}
}
if(q.empty()){
cout<<"YES"<<endl;
for(ll i=0;i<n;i++){
for(ll j=0;j<m;j++){
if((i+j) & 1){
cout<<"R";
}
else{
cout<<"W";
}
}
cout<<endl;
}
continue;
}
while(!q.empty()){
auto elem = q.front();
q.pop();
ll y=elem.first;
ll x=elem.second;
if(vis[y][x]) continue;
vis[y][x]=1;
for(ll dy=-1;dy<=1;dy++){
for(ll dx=-1;dx<=1;dx++){
if(abs(dy)==abs(dx)) continue;
ll ny=y+dy;
ll nx=x+dx;
if(ny<n && ny>=0 && nx<m && nx>=0 && !vis[ny][nx] && arr[ny][nx]==0){
ll tar;
if(arr[y][x]==1){
tar=2;
}
else{
tar=1;
}
arr[ny][nx]=tar;
q.push(make_pair(ny,nx));
}
}
}
}
bool ok=true;
for(ll i=0;i<n && ok;i++){
for(ll j=0;j<m && ok;j++){
if(i-1>=0){
if(arr[i-1][j]==arr[i][j]){
ok=false;
break;
}
}
if(i+1<n){
if(arr[i+1][j]==arr[i][j]){
ok=false;
break;
}
}
if(j-1>=0){
if(arr[i][j-1]==arr[i][j]){
ok=false;
break;
}
}
if(j+1<m){
if(arr[i][j+1]==arr[i][j]){
ok=false;
break;
}
}
}
}
if(ok){
cout<< "YES" <<'\n';
for(ll i=0;i<n;i++){
for(ll j=0;j<m;j++){
if(arr[i][j]==1){
cout<< "R";
}
else{
cout<< "W";
}
}
cout<<'\n';
}
}
else{
cout<< "NO" <<'\n';
}
}
return 0;
}//Code Contributed by Harshit Varshney