QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#752833#9560. Judgementucup-team3555#WA 0ms3720kbC++201.6kb2024-11-16 10:03:212024-11-16 10:03:21

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 10:03:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3720kb
  • [2024-11-16 10:03:21]
  • 提交

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);
	}
}
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'){cout<<"NO"<<endl;return;}
	if(m==1)
	{
		for(int i=1;i<=n;i++)ch[1][i]=ch[i][1];
		swap(n,m);
	}
	if(n==1)
	{
		for(int i=1;i<=m;i++)
		{
			d[i][0]=d[i-1][0];d[i][1]=d[i-1][1];
			if(ch[1][i]=='R')d[i][0]++;
			if(ch[1][i]=='B')d[i][1]++;
		}
		for(int i=1;i<=m;i++)
		{
			if(ch[1][i]=='R'&&d[i-1][1]&&d[m][1]-d[i][1])return NO();
			if(ch[1][i]=='B'&&d[i-1][0]&&d[m][0]-d[i][0])return NO();
		}
	}
	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();
	}
	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: 3616kb

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: 3720kb

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
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES

result:

wrong answer expected NO, found YES [8th token]