QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643961#5071. Check Pattern is GoodKevin5307WA 29ms3800kbC++232.4kb2024-10-16 08:58:042024-10-16 08:58:06

Judging History

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

  • [2024-10-16 08:58:06]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:3800kb
  • [2024-10-16 08:58:04]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
string grid[105];
int n,m;
int cnt[105][105];
int vis[105][105];
void check(int x,int y);
void color(int x,int y,char ch)
{
	grid[x][y]=ch;
	for(int a=0;a<2;a++)
		for(int b=0;b<2;b++)
			if(x>=a&&y>=b&&x-a<n-1&&y-b<m-1)
			{
				cnt[x-a][y-b]--;
				if(cnt[x-a][y-b]==1)
					check(x-a,y-b);
			}
}
void check(int x,int y)
{
	vis[x][y]=1;
	set<char> st;
	for(int a=0;a<2;a++)
		for(int b=0;b<2;b++)
			if(grid[x+a][y+b]!='?')
				st.insert(grid[x+a][y+b]);
	if(sz(st)==1)
	{
		for(int a=0;a<2;a++)
			for(int b=0;b<2;b++)
				if(grid[x+a][y+b]=='?')
					color(x+a,y+b,*st.begin());
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		for(int i=0;i<n;i++)
			cin>>grid[i];
		for(int i=0;i<n-1;i++)
			for(int j=0;j<m-1;j++)
			{
				cnt[i][j]=0;
				vis[i][j]=0;
				for(int x=0;x<2;x++)
					for(int y=0;y<2;y++)
						if(grid[i+x][j+y]=='?')
							cnt[i][j]++;
			}
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				if((i+j)&1) if(grid[i][j]!='?')
					grid[i][j]='B'+'W'-grid[i][j];
		for(int i=0;i<n-1;i++)
			for(int j=0;j<m-1;j++)
				if(cnt[i][j]==1&&!vis[i][j])
					check(i,j);
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				if(grid[i][j]=='?')
					grid[i][j]='B';
		int ans=0;
		for(int i=0;i<n-1;i++)
			for(int j=0;j<m-1;j++)
			{
				set<char> st;
				for(int a=0;a<2;a++)
					for(int b=0;b<2;b++)
						st.insert(grid[i+a][j+b]);
				if(sz(st)==1)
					ans++;
			}
		cout<<ans<<'\n';
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				if((i+j)&1)
					cout<<(char)('B'+'W'-grid[i][j]);
				else
					cout<<grid[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: 3800kb

input:

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

output:

1
BW
WB
1
BWB
WBB
BBW
4
BWB
WBW
BWB

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 29ms
memory: 3676kb

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:

3
BB
BW
WW
WW
BW
WB
BW
WB
BB
2
BW
WB
BW
BW
WW
WB
9
WBBBWWB
WBWBWWW
BWBBWWB
WBWWBWW
BBWBBWB
WWBWWWW
BWBWBWB
WWWWBBW
BBWBBWW
BBWBWBB
6
BWWBWWB
WBBWWWB
BWWBBBW
BBBWBBB
0
B
W
B
B
B
W
W
W
B
W
5
BWWW
WBWB
WWWW
WBWW
BWBW
WWWW
WWWW
WWWW
BWBW
WBWW
6
WBW
WBW
BWB
WBW
WWW
WBW
BWB
WWW
0
W
B
B
W
0
BBBB
WBWB
3
BWB...

result:

wrong answer ans finds a larger answer (test case 6)