QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#399956#5070. Check Pattern is BadtderWA 31ms3736kbC++142.8kb2024-04-26 20:12:202024-04-26 20:12:20

Judging History

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

  • [2024-04-26 20:12:20]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:3736kb
  • [2024-04-26 20:12:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e2 + 5;
int t, n, m; char a[N][N], r[N][N];
const int dx[4] = {-1, -1, 0, 0};
const int dy[4] = {-1, 0, -1, 0};
bool equal(int x1, int y1, int x2, int y2) {
	return (a[x1][y1] == a[x2][y2] || a[x1][y1] == '?' || a[x2][y2] == '?');
}
bool work(int x1, int y1, int x2, int y2) {
	return equal(x1, y1, x2, y2) && equal(x1, y2, x2, y1) && (!equal(x1, y1, x1, y2) || !equal(x1, y1, x2, y1) || !equal(x2, y1, x2, y2) || !equal(x1, y2, x2, y2));
}
char near(int x, int y, int x1, int y1, int x2, int y2) {
	int xx = x, yy = (y == y1 ? y2 : y1);
	return a[xx][yy];
}
int check(int x, int y) {
	// cout<<"check "<<x<<" "<<y<<endl;
	// if(x == 9 && y == 4) {
	// 	cout<<"x = 9, y = 4"<<endl;
	// 	for(int i = 1; i <= n; i++) {
	// 	for(int j = 1; j <= m; j++) cout<<a[i][j];
	// 		cout<<endl;
	// 	}
	// 	cout<<endl;
	// }
	if(a[x][y] != '?') return 1;
	for(int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if(nx < 1 || nx + 1 > n || ny < 1 || ny + 1 > m) continue;
		// cout<<"in "<<nx<<" "<<ny<<endl;
		int b = 1;
		for(int xx = 0; xx < 2 && b; xx++) for(int yy = 0; yy < 2 && b; yy++) {
			int tx = nx + xx, ty = ny + yy;
			if((x != tx || y != ty) && a[tx][ty] == '?') b = 0;
		}
		if(!b) continue;
		if(work(nx, ny, nx + 1, ny + 1))
			if(a[x][y] != '?' && a[x][y] != near(x, y, nx, ny, nx + 1, ny + 1)) {
				// cout<<"check "<<x<<" "<<y<<" = "<<0<<endl;
				return 0;
			} else {
				a[x][y] = near(x, y, nx, ny, nx + 1, ny + 1);
				// if(x == 9 && y == 4) cout<<"a["<<x<<"]["<<y<<"] = "<<a[x][y]<<endl;
			}
	}
	// cout<<"check "<<x<<" "<<y<<" = "<<1<<endl;
	return 1;
}
void solve() {
	cin>>n>>m;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin>>a[i][j];
	int b = 1;
	for(int i = 1; i <= n && b; i++) for(int j = 1; j <= m && b; j++) b = min(b, check(i, j));
	for(int i = n; i >= 1 && b; i--) for(int j = m; j >= 1 && b; j--) b = min(b, check(i, j));
	// for(int i = 1; i <= n; i++) {
	// 	for(int j = 1; j <= m; j++) cout<<a[i][j];
	// 	cout<<endl;
	// }
	if(!b) {
		cout<<"NO"<<endl;
		return;
	}
	cout<<"YES"<<endl;
	// for(int i = 1; i <= n; i++) {
	// 	for(int j = 1; j <= m; j++) cout<<a[i][j];
	// 	cout<<endl;
	// }
	while(1) {
		memcpy(r, a, sizeof(r));
		b = 1;
		for(int i = 1; i <= n && b; i++) for(int j = 1; j <= m && b; j++) {
			b = min(b, check(i, j));
			if(a[i][j] == '?') a[i][j] = ((rand() % 2) ? 'B' : 'W');
		}
		for(int i = 1; i <= n && b; i++) for(int j = 1; j <= m && b; j++) b = min(b, check(i, j));
		if(b) break;
		memcpy(a, r, sizeof(a));
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) cout<<a[i][j];
		cout<<endl;
	}
}
signed main() {
	srand(time(0));
	cin>>t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3736kb

input:

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

output:

YES
BB
WB
NO
YES
BWB
WWW
WWW

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 31ms
memory: 3720kb

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
BB
WB
BB
BW
WW
WB
YES
WBBBWWW
WBWBWWW
BBWBWWB
WWWWBWB
BBWBBWB
WWBBWWW
BWBWWBW
WWWWBBW
BBWBBWW
BWWBWWB
YES
WWWBWWB
BBBWWWB
WWBBBBB
BBBWBBB
YES
B
W
W
B
B
W
W
W
B
B
YES
BBWW
WBWB
WWWW
WBBW
WWWW
BWBW
WWWW
WWWW
BWBW
BWWW
YES
WBW
WBB
BBB
BWB
WWW
WBW
WWW
BWB
YES
W
B
B
W
Y...

result:

wrong answer There is a check pattern in (2, 3) (test case 3)