QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#276209 | #5070. Check Pattern is Bad | rageOfThunder# | WA | 0ms | 3652kb | C++14 | 3.5kb | 2023-12-05 18:09:00 | 2023-12-05 18:09:01 |
Judging History
answer
//-DYUNQIAN -std=c++14 -O2 -Wall
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define mk make_pair
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
return x*f;
}
const int mod=1e9+7;
int ksm(int x,int y,int p=mod){
int ans=1;
for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
void Assert(bool c,int L=0){if(!c){cout<<"Assertion Failed at "<<L<<endl;exit(0);}}
void cmax(int &x,int v){x=max(x,v);}
void cmin(int &x,int v){x=min(x,v);}
string ch="WB";
void solve(){
int n=read(),m=read();
vector<vector<int> >a(n+1);
for(int i=1;i<=n;i++){
a[i].resize(m+1);
for(int j=1;j<=m;j++){
char c=getchar();while(c!='?'&c!='W'&&c!='B')c=getchar();
if(c=='W')a[i][j]=0;
if(c=='B')a[i][j]=1;
if(c=='?')a[i][j]=-1;
if(a[i][j]!=-1)a[i][j]^=((i+j)&1);
}
}
queue<pair<int,int> >q;
auto extend=[&](int x,int y){
if(x>=2&&y>=2){
int 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==3){
bool chk=1;
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x-i][y-j]!=-1&&a[x-i][y-j]!=a[x][y])chk=0;
if(chk){
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x-i][y-j]==-1)a[x-i][y-j]=(a[x][y]^1),q.push(mk(x-i,y-j));
}
}
}
if(x>=2&&y<=m-1){
int 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==3){
bool chk=1;
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x-i][y+j]!=-1&&a[x-i][y+j]!=a[x][y])chk=0;
if(chk){
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x-i][y+j]==-1)a[x-i][y+j]=(a[x][y]^1),q.push(mk(x-i,y+j));
}
}
}
if(x<=n-1&&y>=2){
int 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==3){
bool chk=1;
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x+i][y-j]!=-1&&a[x+i][y-j]!=a[x][y])chk=0;
if(chk){
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x+i][y-j]==-1)a[x+i][y-j]=(a[x][y]^1),q.push(mk(x+i,y-j));
}
}
}
if(x<=n-1&&y<=m-1){
int 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==3){
bool chk=1;
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x+i][y+j]!=-1&&a[x+i][y+j]!=a[x][y])chk=0;
if(chk){
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)if(a[x+i][y+j]==-1)a[x+i][y+j]=(a[x][y]^1),q.push(mk(x+i,y+j));
}
}
}
};
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]!=-1)q.push(mk(i,j));
while(q.size()){
auto t=q.front();q.pop();
extend(t.fi,t.se);
if(q.size()==0){
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]==-1){
a[i][j]=0,q.push(mk(i,j));goto E;
}
E:;
}
}
for(int i=1;i<n;i++)for(int j=1;j<m;j++)if(a[i][j]==a[i+1][j]&&a[i+1][j]==a[i][j+1]&&a[i][j+1]==a[i+1][j+1])return puts("NO"),void();
puts("YES");
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
assert(a[i][j]!=-1);
a[i][j]^=((i+j)&1);
cout<<ch[a[i][j]];if(j==m)puts("");
}
};
signed main(void){
#ifdef YUNQIAN
freopen("in.in","r",stdin);
#endif
int tt=read();while(tt--)solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
NO NO YES BWW WWW WWW
result:
wrong answer ans finds the answer, but out doesn't (test case 1)