QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368482#5070. Check Pattern is BadPYD1WA 19ms3720kbC++144.3kb2024-03-27 09:17:522024-03-27 09:17:54

Judging History

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

  • [2024-03-27 09:17:54]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:3720kb
  • [2024-03-27 09:17:52]
  • 提交

answer

#include <set>
#include <map>
#include <list>
#include <queue>
#include <cmath>
#include <time.h>
#include <random>
#include <bitset>
#include <vector>
#include <cstdio>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mk make_pair
#define fi first
#define se second

inline int read(){
	int t = 0,f = 1;
	register char c = getchar();
	while (c < 48 || c > 57) f = (c == '-') ? -1 : 1,c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return f * t;
}

inline int reads(int *s){
	int t = 0;
	register char c = getchar();
	while (c != 'B' && c != 'W' && c != '?') c = getchar();
	while (c == 'B' || c == 'W' || c == '?'){
		if (c == 'B') s[++t] = 0;
		if (c == 'W') s[++t] = 1;
		if (c == '?') s[++t] = -1;
		c = getchar();
	}
	return t;
}

const int N = 100 + 10,dx[4] = {1,1,-1,-1},dy[4] = {1,-1,1,-1};
int T,n,m,s[N][N],tmp[N][N];

mt19937 myrand((int)time(0));

inline int rnd(int l,int r) {return myrand() % (r - l + 1) + l;}

void trans(){
	for (int i = 1;i <= n;i++){
		for (int j = 1;j <= m;j++) if (((i + j) & 1) && s[i][j] != -1) s[i][j] ^= 1;
	}
}

queue <pair<int,int> > q;

bool run(){
	while (!q.empty()){
		int x = q.front().fi,y = q.front().se;q.pop();
		for (int i = 0;i < 4;i++){
			int xx = x + dx[i],yy = y + dy[i];
			if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
			int cnt0 = (s[x][y] == 0) + (s[x][yy] == 0) + (s[xx][y] == 0) + (s[xx][yy] == 0);
			int cnt1 = (s[x][y] == 1) + (s[x][yy] == 1) + (s[xx][y] == 1) + (s[xx][yy] == 1);
			if (cnt0 == 4 || cnt1 == 4) return 0;
			if (cnt0 == 3){
				// if (s[x][y] == -1) s[x][y] = 1,q.push(mk(x,y));
				if (s[x][yy] == -1) s[x][yy] = 1,q.push(mk(x,yy));
				if (s[xx][y] == -1) s[xx][y] = 1,q.push(mk(xx,y));
				if (s[xx][yy] == -1) s[xx][yy] = 1,q.push(mk(xx,yy));
			}
			if (cnt1 == 3){
				// if (s[x][y] == -1) s[x][y] = 0,q.push(mk(x,y));
				if (s[x][yy] == -1) s[x][yy] = 0,q.push(mk(x,yy));
				if (s[xx][y] == -1) s[xx][y] = 0,q.push(mk(xx,y));
				if (s[xx][yy] == -1) s[xx][yy] = 0,q.push(mk(xx,yy));
			}
		}
	}
	return 1;
}

bool chk(){
	for (int x = 1;x <= n;x++){
		for (int y = 1;y <= m;y++){
			for (int i = 0;i < 4;i++){
				int xx = x + dx[i],yy = y + dy[i];
				if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
				int cnt0 = (s[x][y] == 0) + (s[x][yy] == 0) + (s[xx][y] == 0) + (s[xx][yy] == 0);
				int cnt1 = (s[x][y] == 1) + (s[x][yy] == 1) + (s[xx][y] == 1) + (s[xx][yy] == 1);
				if (cnt0 == 4 || cnt1 == 4) return 0;
			}
		}
	}
	return 1;
}

int Case;

void solve(){
	// ++Case;
	// printf("%d\n",Case);
	n = read(),m = read();
	for (int i = 1;i <= n;i++) reads(s[i]);
	// for (int i = 1;i <= n;i++){
	// 	for (int j = 1;j <= m;j++){
	// 		if (rnd(0,5)) tmp[i][j] = s[i][j] = -1;
	// 		else tmp[i][j] = s[i][j] = rnd(0,1);
	// 		// tmp[i][j] = s[i][j] = rnd(-1,1);
	// 	}
	// }
	// for (int i = 1;i <= n;i++){
	// 		for (int j = 1;j <= m;j++){
	// 			if (s[i][j] == 0) putchar('B');
	// 			else if (s[i][j] == 1) putchar('W');
	// 			else putchar('?');
	// 		}
	// 		puts("");
	// 	}
	trans();
	while (!q.empty()) q.pop();
	for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) if (s[i][j] != -1) q.push(mk(i,j));
	run();
	bool f = 1;
	while (f){
		f = 0;
		for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) if (s[i][j] == -1){
			f = 1;
			s[i][j] = 0,q.push(mk(i,j));
			if (!run()) {puts("NO");return ;}
		}
	}
	// if (!chk()) {
	// 	puts("WA!!!");
	// 	for (int i = 1;i <= n;i++){
	// 		for (int j = 1;j <= m;j++){
	// 			if (tmp[i][j] == 0) putchar('B');
	// 			else if (tmp[i][j] == 1) putchar('W');
	// 			else putchar('?');
	// 		}
	// 		puts("");
	// 	}
	// 	exit(0);
	// }
	// chk();
	puts("YES");
	trans();
	for (int i = 1;i <= n;i++){
		for (int j = 1;j <= m;j++){
			if (s[i][j] == 0) putchar('B');
			else putchar('W');
		}
		puts("");
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
#endif
	T = read();
	while (T--) solve();
	// n = m = 10;
	// while (1) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

YES
BW
WW
NO
YES
BWB
WWW
BWB

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 19ms
memory: 3652kb

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
BW
WW
BB
YES
BW
BB
BW
BW
WW
WB
NO
NO
YES
B
W
B
B
B
W
W
W
B
W
YES
BWWW
WWWB
WWWW
WBWW
WWWW
WWWW
WWWW
WWWW
BWBW
WWWW
YES
WBW
WBW
BBB
WBW
WWW
WBW
BBB
WWW
YES
W
B
B
W
YES
BBBB
WBWB
YES
BWBBBB
WWWBWB
YES
WWWWB
YES
BWBWBW
WWBBBB
BBBWBW
WBWWWW
YES
B
YES
BWB
BBB
WBB
WBB
WWB
WBB
BBW
WBW...

result:

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