QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#508220#5070. Check Pattern is BadyyyyxhWA 3ms3964kbC++141.8kb2024-08-07 09:52:572024-08-07 09:52:58

Judging History

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

  • [2024-08-07 09:52:58]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3964kb
  • [2024-08-07 09:52:57]
  • 提交

answer

#include <queue>
#include <cstdio>
using namespace std;
typedef pair<int,int> pii;
const int N=103;
queue<pii> que;
int n,m;
char s[N][N];
bool inq[N][N];
bool check(int x,int y){
	if(x<1||x>=n) return 0;
	if(y<1||y>=n) return 0;
	if(s[x][y]==s[x+1][y]) return 0;
	if(s[x][y]==s[x][y+1]) return 0;
	if(s[x+1][y+1]==s[x+1][y]) return 0;
	if(s[x+1][y+1]==s[x][y+1]) return 0;
	int tx=-1,ty=-1;
	if(s[x][y]=='?'){
		if(tx<0&&ty<0) tx=x,ty=y;
		else return 0;
	}
	if(s[x+1][y]=='?'){
		if(tx<0&&ty<0) tx=x+1,ty=y;
		else return 0;
	}
	if(s[x][y+1]=='?'){
		if(tx<0&&ty<0) tx=x,ty=y+1;
		else return 0;
	}
	if(s[x+1][y+1]=='?'){
		if(tx<0&&ty<0) tx=x+1,ty=y+1;
		else return 0;
	}
	if(tx<0&&ty<0) return s[x][y]==s[x+1][y+1]&&s[x+1][y]==s[x][y+1];
	if(inq[tx][ty]) return 0;
	s[tx][ty]=s[2*x+1-tx][2*y+1-ty]^21;
	que.emplace(tx,ty);inq[tx][ty]=1;
	return 0;
}
int tt;
void solve(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
	if(tt>=0){
		if(++tt==43){
			for(int i=1;i<=n;++i) printf("%s ",s[i]+1);
			putchar('\n');
		}
		return;
	}
	while(!que.empty()) que.pop();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j) inq[i][j]=0;
	for(int i=1;i<n;++i)
		for(int j=1;j<m;++j)
			if(check(i,j)){puts("NO");return;}
	while(true){
		while(!que.empty()){
			auto [a,b]=que.front();que.pop();
			if(check(a,b)){puts("NO");return;}
			if(check(a-1,b)){puts("NO");return;}
			if(check(a,b-1)){puts("NO");return;}
			if(check(a-1,b-1)){puts("NO");return;}
		}
		for(int i=1;i<=n&&que.empty();++i)
			for(int j=1;j<=m&&que.empty();++j)
				if(s[i][j]=='?'){
					s[i][j]='B';
					inq[i][j]=1;
					que.emplace(i,j);
				}
		if(que.empty()) break;
	}
	puts("YES");
	for(int i=1;i<=n;++i) printf("%s\n",s[i]+1);
}
int main(){
	int tc;
	scanf("%d",&tc);
	if(tc<43) tt=-1;
	while(tc--) solve();
	return 0;
}

詳細信息

Test #1:

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

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: 3ms
memory: 3804kb

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:

B??BW??B? BWBB?BWBW WWBWBB?W? WBBBB?BBW ?BWBBBBBB B???BBBWW BBBB?W?W? BB??B???W 

result:

wrong answer Token parameter [name=yesno] equals to "B??BW??B?", doesn't correspond to pattern "YES|NO" (test case 1)