QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297389 | #5070. Check Pattern is Bad | zzuqy | WA | 15ms | 3508kb | C++14 | 2.6kb | 2024-01-04 13:05:38 | 2024-01-04 13:05:38 |
Judging History
answer
#include<bits/stdc++.h>
#define N 109
using namespace std;
int n,m;
int a[N][N];
int check(int x,int y){
if(x<1||y<1||x>=n||y>=m)return 0;
if(a[x][y]==a[x+1][y+1]&&a[x+1][y]==a[x][y+1]&&a[x][y]+a[x][y+1]==1)return -1;
if((a[x][y]==a[x+1][y+1]||a[x+1][y]==a[x][y+1])&&(a[x][y]+a[x][y+1]==1||a[x+1][y]+a[x+1][y+1]==1))return 2;
if(a[x][y]==a[x+1][y+1]||a[x+1][y]==a[x][y+1])return 1;
return 0;
}
queue<pair<int,int>>q2,q1,q0;
bool paint(int x,int y,int clr){
if(a[x][y]<=1)return 1;
a[x][y]=clr;
for(int tx=x-1;tx<=x;tx++)
for(int ty=y-1;ty<=y;ty++){
int tmp=check(x,y);
if(tmp==-1)return 0;
if(tmp==2)q2.push(make_pair(tx,ty));
if(tmp==1)q1.push(make_pair(tx,ty));
}
return 1;
}
bool solve(){
cin>>n>>m;
while(!q2.empty())q2.pop();
while(!q1.empty())q1.pop();
while(!q0.empty())q0.pop();
for(int i=1;i<=n;i++){
string s;cin>>s;
for(int j=1;j<=m;j++){
if(s[j-1]=='B')a[i][j]=0;
if(s[j-1]=='W')a[i][j]=1;
if(s[j-1]=='?')a[i][j]=i*m+j,q0.push(make_pair(i,j));
}
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
int tmp=check(i,j);
if(tmp==-1)return 0;
if(tmp==2)q2.push(make_pair(i,j));
if(tmp==1)q1.push(make_pair(i,j));
}
}
while(!q2.empty()||!q1.empty()||!q0.empty()){
if(!q2.empty()){
auto tmp=q2.front();q2.pop();
int x=tmp.first,y=tmp.second;
if(check(x,y)==-1)return 0;
if(a[x][y]>=2)if(paint(x,y,a[x+1][y])==0)return 0;
if(a[x+1][y]>=2)if(paint(x+1,y,a[x][y])==0)return 0;
if(a[x][y+1]>=2)if(paint(x,y+1,a[x+1][y+1])==0)return 0;
if(a[x+1][y+1]>=2)if(paint(x+1,y+1,a[x][y+1])==0)return 0;
}
else if(!q1.empty()){
auto tmp=q1.front();q1.pop();
int x=tmp.first,y=tmp.second;
if(check(x,y)==-1)return 0;
if(rand()%2){
if(a[x][y]>=2)if(paint(x,y,a[x+1][y])==0)return 0;
if(a[x+1][y]>=2)if(paint(x+1,y,a[x][y])==0)return 0;
}
else{
if(a[x][y+1]>=2)if(paint(x,y+1,a[x+1][y+1])==0)return 0;
if(a[x+1][y+1]>=2)if(paint(x+1,y+1,a[x][y+1])==0)return 0;
}
}
else{
auto tmp=q0.front();q0.pop();
int x=tmp.first,y=tmp.second;
if(check(x,y)==-1)return 0;
if(paint(x,y,0)==0)return 0;
}
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
int tmp=check(i,j);
if(tmp==-1)return 0;
if(tmp==2)q2.push(make_pair(i,j));
if(tmp==1)q1.push(make_pair(i,j));
}
}
return 1;
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int t;cin>>t;
while(t--){
if(solve()==0)puts("NO");
else{
puts("YES");
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)putchar("BW"[a[i][j]]);putchar('\n');
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3504kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BB BB NO YES BWB WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 3508kb
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 NO NO YES B W B B B W W W B B YES BWWW WWWW WWWW WWBW WWWW WWWW WWWW WWWW BWWW BBWW YES WBW WBB BBB BBB WBW WBW BBB BWB YES W B B B YES BBBB WBBB YES BBBBBB BBWBWB YES WBWBB YES BWBBBB WWBWBB BBBWBB WBWWBW YES B YES BWB BBB WBB BBB WWB BBB BBW BBB...
result:
wrong answer ans finds the answer, but out doesn't (test case 107)