QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590841#5070. Check Pattern is BadDaiRuiChen007WA 13ms3688kbC++171.1kb2024-09-26 12:00:492024-09-26 12:00:49

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 12:00:49]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3688kb
  • [2024-09-26 12:00:49]
  • 提交

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)