QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#752906#9560. Judgementucup-team3555#WA 0ms3652kbC++201.6kb2024-11-16 10:23:502024-11-16 10:23:58

Judging History

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

  • [2024-11-16 10:23:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-11-16 10:23:50]
  • 提交

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;
}

詳細信息

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]