QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643968#5071. Check Pattern is GoodKevin5307WA 73ms3648kbC++232.6kb2024-10-16 09:06:252024-10-16 09:06:26

Judging History

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

  • [2024-10-16 09:06:26]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:3648kb
  • [2024-10-16 09:06:25]
  • 提交

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];
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];
		priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> pq;
		for(int i=0;i<n-1;i++)
			for(int j=0;j<m-1;j++)
				pq.emplace(cnt[i][j],mp(i,j));
		auto update=[&](int x,int y,char ch)
		{
			assert(grid[x][y]=='?');
			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]--;
						pq.emplace(cnt[x-a][y-b],mp(x-a,y-b));
					}
		};
		while(sz(pq))
		{
			int x=pq.top().second.first,y=pq.top().second.second;
			pq.pop();
			if(vis[x][y]) continue;
			vis[x][y]=1;
			set<int> 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]=='?')
							update(x+a,y+b,*st.begin());
		}
		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;
}

詳細信息

Test #1:

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

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: 73ms
memory: 3648kb

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
BWBBWWW
WBWBWWB
BWWWBWW
BBWBBWB
WWBWWWW
BWBWBWB
WWWWBBW
BBWBBWW
BBWBWBB
6
BWWBWWB
WBBWWWB
BWWBBBW
BBBWBBB
0
B
W
B
B
B
W
W
W
B
W
15
BWWW
WBWB
WWWB
WBBW
BWWB
BWBW
WBWB
BWBW
WBWW
BWBW
8
WBW
WWB
WBW
BWB
WBW
WBW
BWB
WWW
0
W
B
B
W
1
BBWB
WWBB
3
BW...

result:

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