QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499593#6723. Grid with ArrowsRailgun2334WA 155ms15248kbC++202.0kb2024-07-31 16:02:552024-07-31 16:02:56

Judging History

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

  • [2024-07-31 16:02:56]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:15248kb
  • [2024-07-31 16:02:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define ull unsigned long long
void solve()
{
	int n,m;
	int ans1=0,ans2=0;
	cin>>n>>m;
	getchar();
	vector<vector<int>>a(n+1,vector<int>(m+1));
	vector<vector<int>>flag(n+1,vector<int>(m+1));
	vector<vector<bool>>ff(n+1,vector<bool>(m+1));
	vector<vector<char>>s(n+1,vector<char>(m+1));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>s[i][j];
		}
		getchar();
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			int x=i,y=j;
			if(s[x][y]=='r')
			{
				int dy=y+a[x][y];
				if(dy<=m)
				{
					flag[x][dy]++;
				}
			}
			else if(s[x][y]=='l')
			{
				int dy=y-a[x][y];
				if(dy>=1)
				{
					flag[x][dy]++;
				}
			}
			else if(s[x][y]=='d')
			{
				int dx=x+a[x][y];
				if(dx<=n)
				{
					flag[dx][y]++;
				}
			}
			else if(s[x][y]=='u')
			{
				int dx=x-a[x][y];
				if(dx>=1)
				{
					flag[dx][y]++;
				}
			}
		}
	}
	int xx=0,yy=0,sum=0;
	int f=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(flag[i][j]==flag[1][1])
				f++;
			if(flag[i][j]==0)
			{
				xx=i;
				yy=j;
				sum++;
			}
		}
	}
	if(f==n*m)
	{
		cout<<"Yes"<<endl;
		return;
	}
	if(sum>=2)
	{
		cout<<"No"<<endl;
		return;
	}
	int ans=0;
	while(!ff[xx][yy])
	{
		ans++;
		ff[xx][yy]=true;
		if(s[xx][yy]=='r')
		{
			int dy=yy+a[xx][yy];
			if(dy<=m)
			{
				yy=dy;
			}
		}
		else if(s[xx][yy]=='l')
		{
			int dy=yy-a[xx][yy];
			if(dy>=1)
			{
				yy=dy;
			}
		}
		else if(s[xx][yy]=='d')
		{
			int dx=xx+a[xx][yy];
			if(dx<=n)
			{
				xx=dx;
			}
		}
		else if(s[xx][yy]=='u')
		{
			int dx=xx-a[xx][yy];
			if(dx<=1)
			{
				xx=dx;
			}
		}
	}
	if(ans==n*m)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}
int main()
{
	ll T = 1;
	cin>>T;
	while (T--)
	{
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3476kb

input:

2
2 3
rdd
url
2 1 1
1 1 2
2 2
rr
rr
1 1
1 1

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #2:

score: -100
Wrong Answer
time: 155ms
memory: 15248kb

input:

1109
5 8
rddddldl
drruludl
rrldrurd
urrrlluu
uurrulrl
4 4 1 2 4 3 1 6
1 3 5 1 1 1 3 6
2 4 1 1 2 1 1 1
2 3 4 2 4 3 3 3
4 1 1 2 2 5 1 5
7 9
rdrddrdll
urrdruldl
ruullrulu
drrlrlddl
rrrdddlll
ruulururl
ruurrlluu
7 1 1 1 2 1 2 3 6
1 7 3 1 3 1 2 1 8
2 2 1 2 4 3 1 2 2
2 2 4 1 1 5 3 3 1
3 4 6 1 2 1 2 7 7
6 ...

output:

Yes
No
No
No
Yes
No
No
Yes
Yes
Yes
No
Yes
No
Yes
Yes
No
Yes
No
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
No
No
Yes
No
Yes
No
No
No
No
Yes
Yes
Yes
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
No
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
...

result:

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