QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499591#6723. Grid with ArrowsRailgun2334RE 0ms3772kbC++202.0kb2024-07-31 16:01:072024-07-31 16:01:07

Judging History

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

  • [2024-07-31 16:01:07]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3772kb
  • [2024-07-31 16:01:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define re read()
#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;
	}
	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: 3772kb

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
Runtime Error

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:

No
No
No

result: