QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#381741#5070. Check Pattern is Badmazihang2022WA 34ms3796kbC++142.8kb2024-04-07 20:43:152024-04-07 20:43:15

Judging History

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

  • [2024-04-07 20:43:15]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:3796kb
  • [2024-04-07 20:43:15]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fir first
#define sec second
#define pii pair<int,int>
using namespace std;

const int maxn=105;
const int inf=0x3f3f3f3f;

namespace Solve {
	char c[maxn][maxn];
	void main(int tid) {
		int n,m;
		cin>>n>>m;
		set<pii> all;
		for(int i=0;i<=n+1;i++) {
			for(int j=0;j<=m+1;j++) {
				c[i][j]='\0';
			}
		}
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=m;j++) {
				cin>>c[i][j];
				if(c[i][j]=='?') {
					all.insert({i,j});
				} else {
					c[i][j]=c[i][j]=='B'?'1':'0';
				}
			}
		}
//		if(tid==221) {
//			for(int i=1;i<=n;i++) {
//				for(int j=1;j<=m;j++) {
//					cout<<c[i][j];
//				}
//				cout<<"\n";
//			}
//		} else if(tid>3) {
//			return ;
//		}
		bool ok=true;
		for(int i=1;i<=n-1;i++) {
			for(int j=1;j<=m-1;j++) {
				if(c[i][j]!='?'&&c[i][j+1]!='?'&&c[i][j]==c[i+1][j+1]&&c[i][j+1]==c[i+1][j]&&c[i][j]!=c[i][j+1]) {
					ok=false;
				}
			}
		}
		queue<pii> q;
		auto ck=[&](int x,int y) {
			if(c[x][y]!='?') {
				return ;
			}
			char ans='?';
			auto ckneq=[&](char c) {
				if(ans==c) {
					ok=false;
				}
			};
			if(c[x-1][y-1]=='0'&&c[x][y-1]=='1'&&c[x-1][y]=='1') {
				ckneq('0');
				ans='1';
			}
			if(c[x-1][y-1]=='1'&&c[x][y-1]=='0'&&c[x-1][y]=='0') {
				ckneq('1');
				ans='0';
			}
			if(c[x-1][y]=='1'&&c[x][y+1]=='1'&&c[x-1][y+1]=='0') {
				ckneq('0');
				ans='1';
			}
			if(c[x-1][y]=='0'&&c[x][y+1]=='0'&&c[x-1][y+1]=='1') {
				ckneq('1');
				ans='0';
			}
			if(c[x][y-1]=='1'&&c[x+1][y]=='1'&&c[x+1][y-1]=='0') {
				ckneq('0');
				ans='1';
			}
			if(c[x][y-1]=='0'&&c[x+1][y]=='0'&&c[x+1][y-1]=='1') {
				ckneq('1');
				ans='0';
			}
			if(c[x][y+1]=='1'&&c[x+1][y]=='1'&&c[x+1][y+1]=='0') {
				ckneq('0');
				ans='1';
			}
			if(c[x][y+1]=='0'&&c[x+1][y]=='0'&&c[x+1][y+1]=='1') {
				ckneq('1');
				ans='0';
			}
			if(ans=='?') {
				return ;
			}
			c[x][y]=ans;
			all.erase({x,y});
			q.push({x,y});
		};
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=m;j++) {
				if(c[i][j]=='?') {
					ck(i,j);
				}
			}
		}
		while(all.size()&&ok) {
			if(q.size()) {
				pii p=q.front();
				q.pop();
				ck(p.fir-1,p.sec+1);
				ck(p.fir-1,p.sec);
				ck(p.fir-1,p.sec+1);
				ck(p.fir,p.sec-1);
				ck(p.fir,p.sec+1);
				ck(p.fir+1,p.sec-1);
				ck(p.fir+1,p.sec);
				ck(p.fir+1,p.sec+1);
			} else {
				pii p=*all.begin();
				all.erase(p);
				c[p.fir][p.sec]='0';
				q.push(p);
			}
		}
		if(!ok) {
			cout<<"NO\n";
			return ;
		}
		cout<<"YES\n";
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=m;j++) {
				cout<<(c[i][j]=='1'?'B':'W');
			}
			cout<<"\n";
		}
	}
}

signed main() {
//	freopen("data.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++) {
		Solve::main(t);
	}
}

詳細信息

Test #1:

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

input:

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

output:

YES
WW
WW
NO
YES
BWW
WWW
WWW

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 34ms
memory: 3576kb

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
WW
WB
BB
WW
BB
YES
WW
WB
BB
BW
WW
WW
NO
NO
YES
B
W
W
B
B
W
W
W
B
W
YES
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
WWWW
YES
WBW
WWW
WWW
WWW
WWW
WWW
WWW
WWW
YES
W
B
W
W
YES
WBWB
WWWB
YES
BWWBBB
WWWWWB
YES
WWWWW
YES
BWWWWW
WWBWWB
BBBWWW
WWWWWW
YES
W
YES
BWB
BBB
WBW
WBB
WWB
WBB
BBW
WWW...

result:

wrong answer There is a check pattern in (0, 0) (test case 1945)