QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673095 | #5070. Check Pattern is Bad | sio_ | WA | 9ms | 3696kb | C++14 | 1.6kb | 2024-10-24 20:32:38 | 2024-10-24 20:33:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int a[maxn][maxn],n,m;
int dx[]={-1,-1,0,0};
int dy[]={-1,0,0,-1};
void dfs(int x,int y)
{
if(x<1||y<1||x>=n||y>=m) return ;
int sum=(a[x][y]+a[x][y+1]+a[x+1][y]+a[x+1][y+1]),sx,sy;
if(abs(sum)!=3) return ;
if(a[x][y]==0) a[x][y]=(-sum)/3,sx=x,sy=y;
if(a[x+1][y]==0) a[x+1][y]=(-sum)/3,sx=x+1,sy=y;
if(a[x][y+1]==0) a[x][y+1]=(-sum)/3,sx=x,sy=y+1;
if(a[x+1][y+1]==0) a[x+1][y+1]=(-sum)/3,sx=x+1,sy=y+1;
for(int k=0;k<4;k++) dfs(sx+dx[k],sy+dy[k]);
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
char c;
cin>>c;
if(c=='B') a[i][j]=1;
if(c=='W') a[i][j]=-1;
if((i+j)%2==0) a[i][j]*=-1;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) dfs(i,j);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(a[i][j]!=0) continue;
a[i][j]=1;
for(int k=0;k<4;k++) dfs(i+dx[k],j+dy[k]);
}
for(int i=1;i<n;i++)
for(int j=1;j<=n;j++)
if(abs(a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1])==4){cout<<"NO\n";return ;}
cout<<"YES\n";
for(int i=1;i<=n;i++,cout<<"\n")
for(int j=1;j<=m;j++)
{
if((i+j)%2==0) a[i][j]*=-1;
// cout<<a[i][j]<<" ";
cout<<((a[i][j]==1)?'B':'W');
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES WB BB NO YES BWB WWW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 9ms
memory: 3696kb
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 BB WW BB YES BB BB BW BW WW BB NO NO NO NO NO NO YES BBBB WWWB YES BBBBBW WWWBWB YES WBWBB NO YES W NO NO YES BWWBBW YES BBWB NO NO NO NO NO NO YES BWWBW YES BBBBBB BBBWWW BWBBBW BWBWBW WWWWBW WWWWWW WBWWBW WWWWBW NO YES BW BB BW NO NO NO NO NO NO NO NO NO NO NO YES BBBWW BBWBW...
result:
wrong answer ans finds the answer, but out doesn't (test case 5)