QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#590841 | #5070. Check Pattern is Bad | DaiRuiChen007 | WA | 13ms | 3688kb | C++17 | 1.1kb | 2024-09-26 12:00:49 | 2024-09-26 12:00:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=105;
int n,m,a[105][105];
void dfs(int i,int j) {
if(i<1||j<1||i>=n||j>=m) return ;
int s=a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1];
if(s!=3&&s!=-3) return ;
if(!a[i][j]) a[i][j]=-s/3,dfs(i-1,j-1);
else if(!a[i+1][j]) a[i+1][j]=-s/3,dfs(i+1,j-1);
else if(!a[i][j+1]) a[i][j+1]=-s/3,dfs(i-1,j+1);
else a[i+1][j+1]=-s/3,dfs(i+1,j+1);
}
void solve() {
cin>>n>>m;
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) {
char c; cin>>c,a[i][j]=(c=='?'?0:(c=='B'?1:-1))*((i+j)&1?-1:1);
}
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]) {
a[i][j]=1,dfs(i-1,j-1),dfs(i-1,j),dfs(i,j-1),dfs(i,j);
}
bool flg=1;
for(int i=1;i<n;++i) for(int j=1;j<m;++j) {
int s=a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1];
flg&=(s!=4&&s!=-4);
}
if(!flg) return cout<<"NO\n",void();
cout<<"YES\n";
for(int i=1;i<=n;++i,cout<<"\n") for(int j=1;j<=m;++j) {
if((i+j)&1) a[i][j]*=-1;
cout<<(a[i][j]>0?'B':'W');
}
}
signed main() {
ios::sync_with_stdio(false);
int T; cin>>T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BW WW NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 3576kb
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 BW BB BW WW BB YES BB WB BB BW WW WW NO NO YES B W W B B W W W B W YES BWWW WWWW WWWW WBWW WWWW WWWW WWWW WWWW BWBW WWWW YES WBW WBW BBW WBW WWW WBW BBW WWW YES W B W W YES BBBB WWWB YES BWBBBB WWWWWB YES WWWWW YES BWBWBW WWBBBB BBBWBW WWWWWW YES W YES BWB BBB WBW WBB WWB WBB BBW WWW...
result:
wrong answer There is a check pattern in (8, 7) (test case 60)