QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#272138#5070. Check Pattern is BadliangbowenWA 0ms3432kbC++142.8kb2023-12-02 16:13:252023-12-02 16:13:33

Judging History

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

  • [2023-12-02 16:13:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3432kb
  • [2023-12-02 16:13:25]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <queue>
#define mk make_pair
using namespace std;
int n, m; char a[105][105];
bool check(int x, int y)
{
	if (a[x][y] == 'B' && a[x + 1][y] == 'W' && a[x][y + 1] == 'W' && a[x + 1][y + 1] == 'B') return false;
	if (a[x][y] == 'W' && a[x + 1][y] == 'B' && a[x][y + 1] == 'B' && a[x + 1][y + 1] == 'W') return false;
	return true;
}
pair <int, int> cover(int x, int y) //把必定能确定的点填掉
{
	int yiw = 0, X = -1, Y = -1;
	for (auto dx : {x, x + 1}) for (auto dy : {y, y + 1})
		if (1 <= dx && dx <= n && 1 <= dy && dy <= m && a[dx][dy] == '?')
			yiw++, X = dx, Y = dy;
	if (yiw != 1) return (yiw == 0 && !check(x, y)) ? mk(-1, -1) : mk(0, 0);

	bool black = false, white = false;
	a[X][Y] = 'B'; if (check(x, y)) black = true;
	a[X][Y] = 'W'; if (check(x, y)) white = true;

	if (black && white) return mk(0, 0);
	else if (!black && !white) return mk(-1, -1);
	else if (black) return a[x][y] = 'B', mk(X, Y);
	else if (white) return a[x][y] = 'W', mk(X, Y);
	return mk(-1, -1);
}
queue <pair <int, int>> q;
bool cover_all()
{
	while (!q.empty())
	{
		auto [x, y] = q.front(); q.pop();
		for (auto dx : {x - 1, x, x + 1}) for (auto dy : {y - 1, y, y + 1})
			if (1 <= dx && dx < n && 1 <= dy && dy < m)
			{
				auto [t1, t2] = cover(dx, dy);
				if (t1 == -1 && t2 == -1) return false;
				else if (t1 == 0 && t2 == 0) a[t1][t2] = '?';
				else if (t1 && t2) q.push({t1, t2});
			}
	}
	return true;
}
bool end_check()
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (a[i][j] == '?') return false;
	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
			if (!check(i, j)) return false;
	return true;
}
inline int rnd(int l = 114514, int r = 1919810) {static int seed = 2333; seed = (((seed * 666666ll + 20050818) % 998244353) ^ 1000000007) % 1004535809; return seed % (r - l + 1) + l;}
void solve()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
		{
			auto [t1, t2] = cover(i, j);
			if (t1 == -1 && t2 == -1) return cout << "NO\n", void();
			else if (t1 == 0 && t2 == 0) a[t1][t2] = '?';
			else if (t1 && t2) q.push({t1, t2});
		}
	if (!cover_all()) return cout << "NO\n", void();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (a[i][j] == '?')
			{
				a[i][j] = (rnd() % 2 ? 'B' : 'W'), q.push({i, j});
				if (!cover_all()) return cout << "NO\n", void();
			}
	if (!end_check()) return cout << "NO\n", void();
	cout << "YES\n";
	for (int i = 1; i <= n; i++, cout << '\n')
		for (int j = 1; j <= m; j++) cout << a[i][j];
}
int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int T;
	cin >> T;
	while (T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3432kb

input:

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

output:

YES
BB
BW
NO
YES
WWW
WWW
WWW

result:

wrong answer (0, 0) should be B, you output W (test case 3)