QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641319 | #5070. Check Pattern is Bad | syxsyx | WA | 23ms | 3840kb | C++14 | 2.8kb | 2024-10-14 19:51:39 | 2024-10-14 19:51:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=105,M=10005;
int T;
int n,m;
char a[N][N];
int typ[N][N];
struct nd
{
int x,y;
bool operator <(const nd &b) const
{
return x<b.x||x==b.x&&y<b.y;
}
};
set <nd> hav1,hav2;
set <nd> ::iterator it;
bool upd(int x,int y)
{
if(x<1||y<1||x>=n||y>=m) return true;
if(1<=typ[x][y]&&typ[x][y]<=2)
{
if(typ[x][y]==1) hav1.erase((nd){x,y});
if(typ[x][y]==2) hav2.erase((nd){x,y});
}
int cnt=(a[x][y]=='?')+(a[x+1][y]=='?')+(a[x][y+1]=='?')+(a[x+1][y+1]=='?');
if(cnt==0&&a[x][y]=='W'&&a[x+1][y+1]=='W'&&a[x+1][y]=='B'&&a[x][y+1]=='B') return false;
if(cnt==0&&a[x][y]=='B'&&a[x+1][y+1]=='B'&&a[x+1][y]=='W'&&a[x][y+1]=='W') return false;
if((a[x][y]==a[x+1][y]||a[x][y]==a[x+1][y+1])&&a[x][y]!='?') cnt=0;
if((a[x+1][y]==a[x+1][y+1]||a[x][y+1]==a[x+1][y+1])&&a[x+1][y+1]!='?') cnt=0;
if(a[x][y]!=a[x+1][y+1]&&a[x][y]!='?') cnt=0;
if(a[x+1][y]!=a[x][y+1]&&a[x+1][y]!='?') cnt=0;
if(cnt==2)
{
if(a[x][y]=='?'&&a[x+1][y]=='?') cnt=0;
if(a[x][y]=='?'&&a[x][y+1]=='?') cnt=0;
if(a[x][y+1]=='?'&&a[x+1][y+1]=='?') cnt=0;
if(a[x+1][y]=='?'&&a[x+1][y+1]=='?') cnt=0;
}
typ[x][y]=cnt;
if(1<=typ[x][y]&&typ[x][y]<=2)
{
if(typ[x][y]==1) hav1.insert((nd){x,y});
if(typ[x][y]==2) hav2.insert((nd){x,y});
}
return true;
}
bool update(int x,int y)
{
if(!upd(x-1,y-1)) return false;
if(!upd(x,y-1)) return false;
if(!upd(x-1,y)) return false;
if(!upd(x,y)) return false;
return true;
}
bool check()
{
for(int i=1;i<n;i++)
for(int j=1;j<m;j++)
if(!upd(i,j)) return false;
while(!hav1.empty()||!hav2.empty())
{
if(!hav1.empty())
{
it=hav1.begin();
int x=(*it).x,y=(*it).y;hav1.erase(it);
// printf("1:%d %d\n",x,y);
int tmpx=0,tmpy=0;
if(a[x][y]=='?') tmpx=x,tmpy=y,a[tmpx][tmpy]=a[x][y+1];
if(a[x+1][y]=='?') tmpx=x+1,tmpy=y,a[tmpx][tmpy]=a[x][y];
if(a[x][y+1]=='?') tmpx=x,tmpy=y+1,a[tmpx][tmpy]=a[x][y];
if(a[x+1][y+1]=='?') tmpx=x+1,tmpy=y+1,a[tmpx][tmpy]=a[x][y+1];
if(!update(tmpx,tmpy)) return false;
continue;
}
if(!hav2.empty())
{
it=hav2.begin();
int x=(*it).x,y=(*it).y;hav2.erase(it);
int tmpx=0,tmpy=0;
if(a[x][y]=='?') tmpx=x,tmpy=y,a[x][y]=a[x+1][y];
if(a[x+1][y]=='?') tmpx=x+1,tmpy=y,a[x+1][y]=a[x][y];
if(!update(tmpx,tmpy)) return false;
continue;
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) if(a[i][j]=='?') a[i][j]='W';
return true;
}
void init()
{
hav1.clear();
hav2.clear();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) typ[n][m]=0;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) scanf(" %c",&a[i][j]);
if(!check()){printf("NO\n");continue;}
printf("YES\n");
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) printf("%c",a[i][j]);printf("\n");}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
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: 23ms
memory: 3816kb
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 BB BW WW BB YES WW BB BW 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 BWWBBW WWWWWB YES WWWWW NO YES W YES BWB WBW WBW WBW WWB BBB BWW WWW YES WWBBWBB WWBWWWW BWWWWBW ...
result:
wrong answer There is a check pattern in (0, 4) (test case 10)