QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#367628 | #850. Edit Distance Yet Again | Harry27182 | WA | 1ms | 3572kb | C++14 | 1.9kb | 2024-03-26 11:06:06 | 2024-03-26 11:06:07 |
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;
while(T--)
{
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';
}
}
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: 0
Wrong Answer
time: 1ms
memory: 3572kb
input:
2 3 4 3 kot plot 5 7 3 zycie porazka
output:
YES 3B
result:
wrong output format Expected integer, but "3B" found