QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#673104 | #5070. Check Pattern is Bad | sio_ | WA | 13ms | 3692kb | C++14 | 1.6kb | 2024-10-24 20:34:47 | 2024-10-24 20:34:55 |
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;
else if(c=='W') a[i][j]=-1;
else a[i][j]=0;
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();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES WB BB NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 3648kb
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 WB BB BB BW WW BW NO NO NO NO NO NO YES WBWB WWWB YES BBWBBB BWWWWB YES WBWBW YES BWWBWB WWBBBB BBBWWB WWWWWW YES W NO YES WBBBWBB BBBWWWB BBWWWBB BWWWBBB BBWBBBW YES BBWBWW YES BBWB YES BBBWBWW BWBWBBB BWBBBBB BBBWBBB BBBBBWW BWBBBBW NO YES BBWBWB BBBBBB BBWBBB BB...
result:
wrong answer ans finds the answer, but out doesn't (test case 5)