QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#367629#5070. Check Pattern is BadHarry27182WA 20ms3592kbC++141.9kb2024-03-26 11:07:392024-03-26 11:07:39

Judging History

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

  • [2024-03-26 11:07:39]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3592kb
  • [2024-03-26 11:07:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char s[105][105];int T,n,m,flag;
int dx[4]={1,1,-1,-1},dy[4]={1,-1,1,-1};
queue<pair<int,int> >q;
void solve()
{
	while(!q.empty())
	{
		int x=q.front().first,y=q.front().second;q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=x+dx[i],ny=y+dy[i];
			if(nx<1||nx>n||ny<1||ny>m)continue;
			int now=(s[x][y]=='B')+(s[nx][y]=='B')+(s[x][ny]=='B')+(s[nx][ny]=='B');
			if(now==4){cout<<"NO\n";flag=1;return;}
			if(now==3)
			{
				if(s[nx][y]=='?')s[nx][y]='W',q.push(make_pair(nx,y));
				if(s[x][ny]=='?')s[x][ny]='W',q.push(make_pair(x,ny));
				if(s[nx][ny]=='?')s[nx][ny]='W',q.push(make_pair(nx,ny));
			}
			now=(s[x][y]=='W')+(s[nx][y]=='W')+(s[x][ny]=='W')+(s[nx][ny]=='W');
			if(now==4){cout<<"NO\n";flag=1;return;}
			if(now==3)
			{
				if(s[nx][y]=='?')s[nx][y]='B',q.push(make_pair(nx,y));
				if(s[x][ny]=='?')s[x][ny]='B',q.push(make_pair(x,ny));
				if(s[nx][ny]=='?')s[nx][ny]='B',q.push(make_pair(nx,ny));
			}
		}
	}
}
int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>T;
	while(T--)
	{
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			cin>>(s[i]+1);
			for(int j=1;j<=m;j++)if((i+j)&1)
			{
				if(s[i][j]=='B')s[i][j]='W';
				else if(s[i][j]=='W')s[i][j]='B';
			}
		}
		for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(s[i][j]!='?')q.push(make_pair(i,j));
		flag=0;solve();
		if(flag==1)continue;
		while(1)
		{
			int ok=1;
			for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ok&=(s[i][j]!='?');
			if(ok)break;
			for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(s[i][j]=='?')
			{
				s[i][j]='B';
				q.push(make_pair(i,j));solve(); 
			}
			if(flag==1)break;
		}
		if(flag==1)continue;
		cout<<"YES\n";
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if((i+j)&1)
				{
					if(s[i][j]=='B')s[i][j]='W';
					else s[i][j]='B';
				}
				cout<<s[i][j];
			}
			cout<<'\n';
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

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
Wrong Answer
time: 20ms
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
BW
BB
BW
BW
WW
WB
NO
NO
YES
B
W
B
B
B
W
W
W
B
W
YES
BWWW
WWWB
WWWW
WBWW
WWWW
WWWW
WWWW
WWWW
BWBW
WWWW
YES
WBW
WBW
BBB
WBW
WWW
WBW
BBB
WWW
YES
W
B
B
W
YES
BBBB
WBWB
YES
BWBBBB
WWWBWB
YES
WWWWB
YES
BWBWBW
WWBBBB
BBBWBW
WBWWWW
YES
B
YES
BWB
BBB
WBB
WBB
WWB
WBB
BBW
WBW...

result:

wrong answer ans finds the answer, but out doesn't (test case 265)