QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#381638 | #5070. Check Pattern is Bad | mazihang2022 | RE | 0ms | 0kb | C++14 | 2.5kb | 2024-04-07 19:48:05 | 2024-04-07 19:48:06 |
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) {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n,m;
cin>>n>>m;
set<pii> all;
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';
}
}
}
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]) {
cout<<"NO\n";
return ;
}
}
}
queue<pii> q;
auto ck=[&](int x,int y) {
if(c[x][y]!='?') {
return ;
}
char ans='?';
auto ckneq=[&](char c) {
assert(ans!=c);
};
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()) {
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);
}
}
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() {
int T;
cin>>T;
for(int t=1;t<=T;t++) {
Solve::main(t);
}
}
详细
Test #1:
score: 0
Runtime Error
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?