QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297385#5070. Check Pattern is BadzzuqyWA 19ms3504kbC++142.4kb2024-01-04 12:57:042024-01-04 12:57:05

Judging History

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

  • [2024-01-04 12:57:05]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:3504kb
  • [2024-01-04 12:57:04]
  • 提交

answer

#include<bits/stdc++.h>
#define N 109
using namespace std;
int n,m;
int a[N][N];
int check(int x,int y){
	if(x<1||y<1||x>=n||y>=m)return 0;
	if(a[x][y]==a[x+1][y+1]&&a[x+1][y]==a[x][y+1]&&a[x][y]+a[x][y+1]==1)return -1;
	if((a[x][y]==a[x+1][y+1]||a[x+1][y]==a[x][y+1])&&(a[x][y]+a[x][y+1]==1||a[x+1][y]+a[x+1][y+1]==1))return 2;
	if(a[x][y]==a[x+1][y+1]||a[x+1][y]==a[x][y+1])return 1;
	return 0;
}
queue<pair<int,int>>q2,q1,q0;
bool paint(int x,int y,int clr){
	if(a[x][y]<=1)return 1;
	a[x][y]=clr;
	for(int tx=x-1;tx<=x;tx++)
		for(int ty=y-1;ty<=y;ty++){
			int tmp=check(x,y);
			if(tmp==-1)return 0;
			if(tmp==2)q2.push(make_pair(tx,ty));
			if(tmp==1)q1.push(make_pair(tx,ty));
		}
	return 1;
}
bool solve(){
	cin>>n>>m;
	while(!q2.empty())q2.pop();
	while(!q1.empty())q1.pop();
	while(!q0.empty())q0.pop();
	for(int i=1;i<=n;i++){
		string s;cin>>s;
		for(int j=1;j<=m;j++){
			if(s[j-1]=='B')a[i][j]=0;
			if(s[j-1]=='W')a[i][j]=1;
			if(s[j-1]=='?')a[i][j]=i*m+j,q0.push(make_pair(i,j));
		}
	}
	
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			int tmp=check(i,j);
			if(tmp==-1)return 0;
			if(tmp==2)q2.push(make_pair(i,j));
			if(tmp==1)q1.push(make_pair(i,j));
		}
	}
	while(!q2.empty()||!q1.empty()||!q0.empty()){
		if(!q2.empty()){
			auto tmp=q2.front();q2.pop();
			int x=tmp.first,y=tmp.second;
			if(check(x,y)==-1)return 0;
			if(a[x][y]>2)if(paint(x,y,a[x+1][y])==0)return 0;
			if(a[x+1][y]>2)if(paint(x+1,y,a[x][y])==0)return 0;
			if(a[x][y+1]>2)if(paint(x,y+1,a[x+1][y+1])==0)return 0;
			if(a[x+1][y+1]>2)if(paint(x+1,y+1,a[x][y+1])==0)return 0;
		}
		else if(!q1.empty()){
			auto tmp=q1.front();q1.pop();
			int x=tmp.first,y=tmp.second;
			if(check(x,y)==-1)return 0;
			if(a[x][y]>2)if(paint(x,y,a[x+1][y])==0)return 0;
			if(a[x+1][y]>2)if(paint(x+1,y,a[x][y])==0)return 0;
			if(a[x][y+1]>2)if(paint(x,y+1,a[x+1][y+1])==0)return 0;
			if(a[x+1][y+1]>2)if(paint(x+1,y+1,a[x][y+1])==0)return 0;
		} 
		else{
			auto tmp=q0.front();q0.pop();
			int x=tmp.first,y=tmp.second;
			if(check(x,y)==-1)return 0;
			if(paint(x,y,0)==0)return 0;
		}
	}	
	return 1;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int t;cin>>t;
	while(t--){
		if(solve()==0)puts("NO");
		else{
			puts("YES");
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++)putchar("BW"[a[i][j]]);putchar('\n'); 
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3428kb

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: 19ms
memory: 3504kb

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
YES
B
W
B
B
B
W
W
W
B
B
YES
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
BWWW
BWWW
YES
WBW
WBB
BBB
BBB
WBW
WBW
BBB
BWB
YES
W
B
B
B
YES
BBBB
WBBB
YES
BBBBBB
BBWBWB
YES
WBWBB
YES
BWBBBB
WWBWBB
BBBWBB
WBWWBW
YES
B
YES
BWB
BBB
WBB
BBB
WWB
BBB
BBW
BBB...

result:

wrong answer There is a check pattern in (0, 3) (test case 51)