QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368477#5070. Check Pattern is BadPYD1WA 18ms3560kbC++142.9kb2024-03-27 09:01:342024-03-27 09:01:36

Judging History

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

  • [2024-03-27 09:01:36]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3560kb
  • [2024-03-27 09:01:34]
  • 提交

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];

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;
}

void solve(){
	n = read(),m = read();
	for (int i = 1;i <= n;i++) reads(s[i]);
	trans();
	while (!q.empty()) q.pop();
	for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) 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 ;}
		}
	}
	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();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 18ms
memory: 3560kb

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)