QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571034#5070. Check Pattern is BadjuruoAWA 24ms3996kbC++143.0kb2024-09-17 20:04:132024-09-17 20:04:14

Judging History

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

  • [2024-09-17 20:04:14]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:3996kb
  • [2024-09-17 20:04:13]
  • 提交

answer

#include <bits/stdc++.h>
using std::bitset;
using std::cout;
using std::deque;
using std::endl;
using std::greater;
using std::lower_bound;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multimap;
using std::multiset;
using std::nth_element;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse; 
using std::set;
using std::sort;
using std::sqrt;
using std::stable_sort;
using std::string;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
typedef long long li;
typedef long double lf;

inline li read(){
	li ans = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		f = (ch == '-') ? -1 : 1;
		ch = getchar();
	}
	while(ch <= '9' && ch >= '0'){
		ans = ans * 10 + (ch ^ 48);
		ch = getchar();
	}
	return ans * f;
} 

li n, m;
char a[110][110];
queue<pair<li, li>> q;

bool isfull(){
	if(q.size()) return 0;
	for(li i = 1; i <= n; i++){
		for(li j = 1; j <= m; j++){
			if(a[i][j] == '?'){
				a[i][j] = 'B';
				q.push({i, j});
				return 0;
			}
		}
	}
	return 1;
}

char change(char x){return x == 'W' ? 'B' : 'W';}

bool check(li x, li y){
	if(x <= 0 || y <= 0 || x >= n || y >= m) return 1;
	li cnt = 0;
	for(li i = x; i <= x + 1; i++) for(li j = y; j <= y + 1; j++) if(a[i][j] == '?') cnt++;
	if(cnt > 1) return 1;
	if(cnt == 0){
		return a[x][y] == a[x + 1][y] || a[x][y] == a[x][y + 1] || a[x][y] != a[x + 1][y + 1];
	}
	if(a[x][y] == a[x + 1][y + 1]){
		if(a[x + 1][y] == '?' && a[x][y] != a[x][y + 1]){
			a[x + 1][y] = change(a[x][y + 1]);
			q.push({x + 1, y});
		}
		if(a[x][y + 1] == '?' && a[x + 1][y] != a[x][y]){
			a[x][y + 1] = change(a[x + 1][y]);
			q.push({x, y + 1});
		}
	}
	if(a[x + 1][y] == a[x][y + 1]){
		if(a[x][y] == '?' && a[x + 1][y] != a[x + 1][y + 1]){
			a[x][y] = change(a[x + 1][y + 1]);
			q.push({x, y});
		}
		if(a[x + 1][y + 1] == '?' && a[x + 1][y] != a[x][y]){
			a[x + 1][y + 1] = change(a[x][y]);
			q.push({x + 1, y + 1});
		}
	}
	return 1;
}

int main(){
    // freopen("wonderful.ans", "r", stdin);
    // freopen("www.ww", "w", stdout); 
	li T = read();
	while(T--){
		n = read(), m = read();
		while(q.size()) q.pop();
		for(li i = 1; i <= n; i++){
			scanf("%s", a[i] + 1);
			for(li j = 1; j <= m; j++) if(a[i][j] == '?') q.push({i, j});
		}
		li fl = 1;
		while(fl && !isfull()){
			while(q.size()){
				auto u = q.front(); q.pop();
				// cout << u.first << " " << u.second << endl;
				if(!check(u.first, u.second)){
					fl = 0;
					break;
				}
				if(!check(u.first - 1, u.second)){
					fl = 0;
					break;
				}
				if(!check(u.first, u.second - 1)){
					fl = 0;
					break;
				}
				if(!check(u.first - 1, u.second - 1)){
					fl = 0;
					break;
				}
			}
		}
		if(!fl) puts("NO");
		else{
			puts("YES");
			for(li i = 1; i <= n; i++){
				for(li j = 1; j <= m; j++) putchar(a[i][j]);
				puts("");
			}
		}
	}
    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

YES
BB
BB
NO
YES
BWB
WWW
BWB

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 24ms
memory: 3964kb

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
WB
BB
YES
BB
BB
BB
BW
WW
BB
YES
WBBBWBB
BBBBWWW
BBBBWWB
BBWWBWB
BBWBBWB
WWBBWWB
BWBWWBB
WWWWBBW
BBWBBBW
BBWBWBB
YES
BBWBWWB
BBBWWWB
BWBBBBB
BBBWBBB
YES
B
W
B
B
B
W
W
W
B
B
YES
BBWW
WBWB
WWWB
BBWW
BWWB
BWWW
WWWB
BWWW
BBBW
BBBW
YES
WBW
WBB
BBB
BBB
WBW
WBW
BBB
BWB
YES
W
B
B
B
Y...

result:

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