QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640421#5070. Check Pattern is BadFlamireTL 1ms4024kbC++172.1kb2024-10-14 12:13:272024-10-14 12:13:27

Judging History

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

  • [2024-10-14 12:13:27]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4024kb
  • [2024-10-14 12:13:27]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int,int>
#define s1 first
#define s2 second
using namespace std;
int n,m,t,cc;char s[111][111];bool ok;
int toi(char c){return (c=='W')+2*(c=='?');}
char toc[11]="BW?";
struct oper{int x,y;char c;};
queue<oper> q;
set<pii> st;
void check(int x,int y)
{
	int c[3]={0,0,0};
	++c[toi(s[x][y])];
	++c[toi(s[x][y+1])];
	++c[toi(s[x+1][y])];
	++c[toi(s[x+1][y+1])];
	if(max(c[0],c[1])==4)ok=0;
	else if(!c[2])return;
	else if(max(c[0],c[1])==3)
	{
		int ix=0,iy=0;
		if(s[x][y]=='?')ix=x,iy=y;
		if(s[x+1][y]=='?')ix=x+1,iy=y;
		if(s[x][y+1]=='?')ix=x,iy=y+1;
		if(s[x+1][y+1]=='?')ix=x+1,iy=y+1;
		// printf("check (%d,%d) force (%d,%d)=%c\n",x,y,ix,iy,toc[c[0]==3]);
		q.push({ix,iy,toc[c[0]==3]});
	}
	else return;
}
void proc(int x,int y,char c)
{//printf("proc((%d,%d),%c)\n",x,y,c);
	if(s[x][y]!='?')
	{
		if(s[x][y]!=c)ok=0;
	}
	else
	{
		--cc;st.erase({x,y});
		s[x][y]=c;
		if(x>1&&y>1)check(x-1,y-1);
		if(x>1&&y<m)check(x-1,y);
		if(x<m&&y>1)check(x,y-1);
		if(x<m&&y<m)check(x,y);
	}
}
int main()
{
	scanf("%d",&t);while(t--)
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;++i)scanf("%s",s[i]+1);cc=0;ok=1;
		for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(s[i][j]!='?'&&(i+j&1))s[i][j]^='B'^'W';
		// printf("s:\n");
		// for(int i=1;i<=n;++i)printf("%s\n",s[i]+1);
		st.clear();
		for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(s[i][j]=='?')st.insert({i,j}),++cc;
		while(!q.empty())q.pop();
		for(int i=1;i<n;++i)for(int j=1;j<m;++j)check(i,j);
		while(cc&&ok)
		{
			while(!q.empty()&&ok)
			{
				oper p=q.front();q.pop();
				// printf("p:(%d,%d)=%c\n",p.x,p.y,p.c);
				proc(p.x,p.y,p.c);
			}
			if(!ok)break;
			if(!st.empty())
			{
				pii x=*st.begin();st.erase(st.begin());
				q.push({x.s1,x.s2,'B'});
			}
		}
		if(!ok)printf("NO\n");
		else
		{
			printf("YES\n");
			for(int i=1;i<=n;++i)
			{
				for(int j=1;j<=m;++j)
				{
					putchar(s[i][j]^(i+j&1)*('B'^'W'));
				}
				putchar(10);
			}
		}
		fflush(stdout);
	}
	fclose(stdin);fclose(stdout);return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 2
??
??
3 3
BW?
W?B
?BW
3 3
BW?
W?W
?W?

output:

YES
BW
WW
NO
YES
BWB
WWW
BWB

result:

ok ok (3 test cases)

Test #2:

score: -100
Time Limit Exceeded

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:

NO
YES
BW
BB
BW
BW
WW
WB
NO
NO
YES
B
W
B
B
B
W
W
W
B
W
NO
YES
WBW
WBW
BBB
WBW
WWW
WBW
BBB
WWW
YES
W
B
B
W
NO
NO
YES
WWWWW
YES
BWBWBW
WWBBBB
BBBWBW
WBWWWW
YES
B
NO
YES
BWBBBBB
WWBBWBW
BWBWWBB
BBBBWBW
BBBBBBB
NO
YES
BBBB
YES
BWBWBWW
BWWWBBW
BWBBBBB
BBBWBBW
BWBBBWW
BBBBBBW
NO
YES
BWBWBB
BBBBBB
BWWBBB
B...

result: