QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276201 | #5070. Check Pattern is Bad | rageOfThunder# | WA | 27ms | 3620kb | C++14 | 3.5kb | 2023-12-05 18:03:29 | 2023-12-05 18:03:29 |
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]!=0)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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES WB BB NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 27ms
memory: 3620kb
input:
10000 9 2 BB BW WW WW ?W ?B B? W? BB 6 2 ?? ?B B? BW WW ?? 10 7 WBBBW?? ???BWWW ???BWWB ??WWBW? BBWBBWB WWB?WW? BWBW??? WWWWBBW BBWBB?W B?W?W?B 4 7 ??WBWWB ?BBWWWB ?W?BBB? BBBWBBB 10 1 B W ? B B W W W B ? 10 4 ??WW W?W? WWW? ???W ?W?? ?W?W W?W? ?W?W ???W ???W 8 3 WBW W?? ??? ??? W?W W?W ??? ?W? 4 1 ...
output:
YES BB BW WW WW WW BB BB WW BB YES WB BB BB BW WW BW NO NO YES B W W B B W W W B B YES WBWW WWWW WWWB BWWW WWWB BWWW WWWB BWWW WWWW BWBW YES WBW WWW WBW BBB WBW WWW WBW WWW YES W B W B YES WBWB WWWB YES BBWBBB BWWWWB YES WBWBW YES BWWBWB WWBBBB BBBWWB WWWWWW YES W YES BWB BBB WBW BBB WWB BBB BBW BWW...
result:
wrong answer ans finds the answer, but out doesn't (test case 25)