这题很容易想到的一点是对于
接下来就是处理它周围格子了,我们就必须按着遍历顺序相反的方向开始弄上面这类格子,相同方向的接下来会遍历到。
那么如果不存在上述格子,且仍还有
最后的工作就是检查是否存在check patterns了
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
using ll=long long;
ll tt,n,m,a[(int)109][(int)109] ;
char c;
void dfs(int x,int y){
if(x<=0 || y<=0 || x>=n || y>=m)return;
ll p=-1,q=-1,cnt=0;
for(int i=0;i<=1;++i)for(int j=0;j<=1;++j)cnt+=a[x+i][y+j]==1;
if(cnt!=1)return;
for(int i=0;i<=1;++i)for(int j=0;j<=1;++j)if(a[x+i][y+j]==1){p=i,q=j;}
if(a[x+!p][y+q]==a[x+p][y+!q]&&(a[x+!p][y+q]^a[x+!p][y+!q])==1){
a[x+p][y+q]=a[x+!p][y+q];
for(int i=0;i<=1;++i)for(int j=0;j<=1;++j)dfs(x+p-i,y+q-j);//back
}
}
bool solve(){
for(int i=1;i<n;++i){
for(int j=1;j<m;++j){
dfs(i,j);
}
}
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j){
if(a[i][j]==1){
a[i][j]=3;
for(int k=0;k<=1;++k)for(int l=0;l<=1;++l)dfs(i-k,j-l);
}
}
for(int i=1;i<n;++i)for(int j=1;j<m;++j){
if(a[i][j]==a[i+1][j+1]&&a[i+1][j]==a[i][j+1]&&a[i][j]!=a[i+1][j])return false;
}
return true;
}
int main()
{
for(scanf("%lld",&tt);tt;tt-=1){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
scanf(" %c",&c);
if(c=='?')a[i][j]=1;
else if(c=='B')a[i][j]=2;
else a[i][j]=3;
}
a[i][m+1]=0;
}
for(int i=1;i<=m+1;++i)a[n+1][m]=0;
if(solve()){
printf("%s","YES\n");
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j)printf("%c",a[i][j]==2?'B':'W');
printf("\n");
}
}else printf("%s","NO\n");
}
return 0;
}