QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#752906 | #9560. Judgement | ucup-team3555# | WA | 0ms | 3652kb | C++20 | 1.6kb | 2024-11-16 10:23:50 | 2024-11-16 10:23:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=503;
int n,m,sx,sy,tx,ty,d[N][2];
char ch[N][N];
bool vis1[N][N],vis2[N][N];
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
bool Ok(int x,int y){return 1<=x&&x<=n&&1<=y&&y<=m&&ch[x][y]!='.';}
void Dfs1(int x,int y)
{
if(vis1[x][y])return;
vis1[x][y]=1;
for(int i:{0,1,2,3})
{
int kx=x+dx[i],ky=y+dy[i];
if(Ok(kx,ky)&&(kx!=tx||ky!=ty))Dfs1(kx,ky);
}
}
void Dfs2(int x,int y)
{
if(vis2[x][y])return;
vis2[x][y]=1;
for(int i:{0,1,2,3})
{
int kx=x+dx[i],ky=y+dy[i];
if(Ok(kx,ky)&&(kx!=sx||ky!=sy))Dfs2(kx,ky);
}
}
bool NB(int x,int y)
{
for(int o:{0,1,2,3})
{
int kx=x+dx[o],ky=y+dy[o];
if(Ok(x,y)&&ch[x][y]==ch[kx][ky])return 0;
}
return 1;
}
void NO(){cout<<"NO"<<endl;}
void YES(){cout<<"YES"<<endl;}
void Solve()
{
cin>>n>>m>>sx>>sy>>tx>>ty;
for(int i=1;i<=max(n,m)+1;i++)d[i][0]=d[i][1]=0;
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>ch[i][j];
for(int i=1;i<=max(n,m)+1;i++)for(int j=1;j<=max(n,m)+1;j++)vis1[i][j]=vis2[i][j]=0;
if(ch[sx][sy]!='R'||ch[tx][ty]!='B')return NO();
if(m==1)
{
for(int i=1;i<=n;i++)ch[1][i]=ch[i][1];
swap(n,m);
}
Dfs1(sx,sy);Dfs2(tx,ty);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
{
if(ch[i][j]=='R'&&!vis1[i][j])return NO();
if(ch[i][j]=='B'&&!vis2[i][j])return NO();
}
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(Ok(i,j))
{
for(int o:{0,1,2,3})
{
int x=i+dx[o],y=i+dy[o];
if(!Ok(x,y)&&ch[i][j]!=ch[x][y])continue;
if(NB(i,j)&&NB(x,y))return NO();
}
}
return YES();
}
int main()
{
int T;cin>>T;
while(T--)Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
4 3 3 1 1 1 2 RBB RRR BBR 6 6 1 1 6 6 RRRRRR BBBBBR BRRRBR BRBBBR BRRRRR BBBBBB 5 5 3 3 4 4 BBR.B BBR.B RRR.B ...BB BBBB. 1 5 1 1 1 3 RBBBR
output:
YES YES NO NO
result:
ok 4 token(s): yes count is 2, no count is 2
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3652kb
input:
18 4 4 3 3 2 2 .... .BB. .BR. .... 7 8 5 6 3 3 ..RRRRRR ..R....R BBBBBB.R B.B..R.R B.RRRRRR B....B.. BBBBBB.. 5 2 3 1 3 2 B. BR RB BR .R 3 3 2 2 1 2 .BB BRB BBB 3 3 1 2 3 2 RRR ... BBB 3 3 1 1 1 3 RRB ... BRR 3 3 1 1 3 1 RRB ... BRR 3 3 3 1 1 1 BBR ..R RBB 3 3 2 2 2 1 .BB BRB .RB 1 2 1 1 1 2 RB 2 2 ...
output:
YES YES NO YES YES NO NO YES NO YES NO NO NO NO NO NO NO NO
result:
wrong answer expected YES, found NO [3rd token]