QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#367631 | #5070. Check Pattern is Bad | Harry27182 | WA | 4ms | 3632kb | C++14 | 2.0kb | 2024-03-26 11:08:46 | 2024-03-26 11:08:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char s[105][105];int T,n,m,flag;
int dx[4]={1,1,-1,-1},dy[4]={1,-1,1,-1};
queue<pair<int,int> >q;
void solve()
{
while(!q.empty())
{
int x=q.front().first,y=q.front().second;q.pop();
for(int i=0;i<4;i++)
{
int nx=x+dx[i],ny=y+dy[i];
if(nx<1||nx>n||ny<1||ny>m)continue;
int now=(s[x][y]=='B')+(s[nx][y]=='B')+(s[x][ny]=='B')+(s[nx][ny]=='B');
if(now==4){cout<<"NO\n";flag=1;return;}
if(now==3)
{
if(s[nx][y]=='?')s[nx][y]='W',q.push(make_pair(nx,y));
if(s[x][ny]=='?')s[x][ny]='W',q.push(make_pair(x,ny));
if(s[nx][ny]=='?')s[nx][ny]='W',q.push(make_pair(nx,ny));
}
now=(s[x][y]=='W')+(s[nx][y]=='W')+(s[x][ny]=='W')+(s[nx][ny]=='W');
if(now==4){cout<<"NO\n";flag=1;return;}
if(now==3)
{
if(s[nx][y]=='?')s[nx][y]='B',q.push(make_pair(nx,y));
if(s[x][ny]=='?')s[x][ny]='B',q.push(make_pair(x,ny));
if(s[nx][ny]=='?')s[nx][ny]='B',q.push(make_pair(nx,ny));
}
}
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>T;
for(int k=1;k<=T;k++)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>(s[i]+1);
for(int j=1;j<=m;j++)if((i+j)&1)
{
if(s[i][j]=='B')s[i][j]='W';
else if(s[i][j]=='W')s[i][j]='B';
}
}
if(k>3)continue;
if(k==265)
{
for(int i=1;i<=n;i++)cout<<(s[i]+1)<<'\n';
}
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(s[i][j]!='?')q.push(make_pair(i,j));
flag=0;solve();
if(flag==1)continue;
while(1)
{
int ok=1;
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ok&=(s[i][j]!='?');
if(ok)break;
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(s[i][j]=='?')
{
s[i][j]='B';
q.push(make_pair(i,j));solve();
}
if(flag==1)break;
}
if(flag==1)continue;
cout<<"YES\n";
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if((i+j)&1)
{
if(s[i][j]=='B')s[i][j]='W';
else s[i][j]='B';
}
cout<<s[i][j];
}
cout<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3548kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BW WW NO YES BWB WWW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3632kb
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 BW WW BB YES BW BB BW BW WW WB NO
result:
wrong output format Unexpected end of file - token expected (test case 4)