QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89956 | #5070. Check Pattern is Bad | xin_chen | WA | 13ms | 3568kb | C++14 | 1.7kb | 2023-03-21 21:03:06 | 2023-03-21 21:03:10 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define LL inline ll
#define I inline int
#define V inline void
#define FOR(i,a,b) for(int i=(a),i##i=(b);i<=i##i;++i)
#define ROF(i,a,b) for(int i=(a),i##i=(b);i>=i##i;--i)
// #define gc (_ft==_fs&&(_ft=(_fs=buf)+fread(buf,1,1<<20,stdin),_ft==_fs))?0:*_fs++
#define gc getchar()
using namespace std;
const int N=110,M=1e5,inf=998244353;
char buf[1<<20],*_fs,*_ft;
LL read(){
ll w=0,p=0; char ch=gc;
while(!isdigit(ch)) w=ch=='-',ch=gc;
while(isdigit(ch)) p=p*10+ch-'0',ch=gc;
return w?-p:p;
}
int n,m;
char ch[N][N];
V sol(){
FOR(i,1,n) FOR(j,1,m) if(ch[i][j]=='?'){
int x=0,y=0;
if(ch[i][j+1]=='B') x++;
if(ch[i][j-1]=='B') x++;
if(ch[i+1][j]=='B') x++;
if(ch[i-1][j]=='B') x++;
if(ch[i][j+1]=='W') y++;
if(ch[i][j-1]=='W') y++;
if(ch[i+1][j]=='W') y++;
if(ch[i-1][j]=='W') y++;
if(x>=y) ch[i][j]='B';
else ch[i][j]='W';
}
return ;
}
I ck(){
FOR(i,1,n) FOR(j,1,n) {
if(ch[i-1][j-1]=='W'&&ch[i-1][j]=='B'&&ch[i][j-1]=='B'&&ch[i][j]=='W') return 0;
if(ch[i-1][j-1]=='B'&&ch[i-1][j]=='W'&&ch[i][j-1]=='W'&&ch[i][j]=='B') return 0;
}
return 1;
}
int main(){
int T=read();
while(T--){
n=read(),m=read();
FOR(i,1,n) scanf("%s",ch[i]+1);
sol();
if(!ck()) cout<<"NO"<<'\n';
else {
cout<<"YES"<<'\n';
FOR(i,1,n) {
FOR(j,1,m) cout<<ch[i][j];
cout<<'\n';
}
}
}
return 0;
}
/*
3
2 2
??
??
3 3
BW?
W?B
?BW
3 3
BW?
W?W
?W?
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3360kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BB BB NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 3568kb
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 WB BB YES BB BB BB BW WW BB NO NO NO YES WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW YES WBW WBB WBB WBB WWW WWW WWW WWW YES W B B B YES BBBB WBBB YES BBBBBB BBWWWB YES WWWWW NO YES W YES BWB BBB WBB WBB WWB BBB BBW BBW YES BBBBBBB BBBBBBB BBBBBBB BBBBBBB BBBBBBB YES B...
result:
wrong answer ans finds the answer, but out doesn't (test case 5)