QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#272012#5070. Check Pattern is BadliangbowenWA 10ms3632kbC++142.4kb2023-12-02 15:39:252023-12-02 15:39:26

Judging History

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

  • [2023-12-02 15:39:26]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3632kb
  • [2023-12-02 15:39: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)
			yiw++, X = dx, Y = dy;
	if (yiw != 1) return check(x, y) ? mk(0, 0) : mk(-1, -1);

	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] = 'W', mk(X, Y);
	else if (white) return a[x][y] = 'B', 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}) for (auto dy : {y - 1, y})
			if (1 <= dx && dx < n && 1 <= dy && dy < m)
			{
				auto [genshin, impact] = cover(dx, dy);
				if (genshin == -1 && impact == - 1) return false;
				else if (genshin && impact) q.push({genshin, impact});
			}
	}
	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 [x, y] = cover(i, j);
			if (x == -1 && y == -1) return cout << "NO\n", void();
			else if (x && y) q.push({x, y});
		}
	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();
			}
	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: 100
Accepted
time: 0ms
memory: 3608kb

input:

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

output:

YES
BB
BW
NO
YES
BWB
WWW
BWB

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 3632kb

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
BB
WW
BB
YES
WW
BB
BW
BW
WW
BB
NO
NO
YES
B
W
B
B
B
W
W
W
B
B
NO
NO
YES
W
B
B
B
YES
WBWB
WBWB
NO
YES
WBWBW
NO
YES
B
NO
NO
YES
BWWBWW
YES
BBWB
NO
NO
NO
NO
NO
NO
YES
BBWBW
NO
NO
YES
BW
BB
BB
NO
NO
NO
NO
YES
W
B
B
NO
NO
YES
W
W
W
B
B
W
W
NO
YES
WWWW
WWWW
WWWB
YES
W
B
B
YES
WWWBW
BW...

result:

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