QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710855#6723. Grid with ArrowsxunxxxxWA 67ms13936kbC++231.5kb2024-11-04 22:36:572024-11-04 22:36:59

Judging History

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

  • [2024-11-04 22:36:59]
  • 评测
  • 测评结果:WA
  • 用时:67ms
  • 内存:13936kb
  • [2024-11-04 22:36:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int>>a(n+1,vector<int>(m+1));
	vector<vector<int>>b(n+1,vector<int>(m+1));
	vector<vector<int>>id(n+1,vector<int>(m+1));
	
	int cnt=1;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) 
	{
		char ch;
		cin>>ch;
		if(ch=='r') a[i][j]=1;
		else if(ch=='l') a[i][j]=2;
		else if(ch=='u') a[i][j]=3;
		else a[i][j]=4;
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) id[i][j]=cnt++;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>b[i][j];
	
	vector<int>in(n*m+1,0);
	vector<int>g(n*m+1,0);
	
	for(int i=1;i<=n;i++) 
	for(int j=1;j<=m;j++) 
	{
		int ni=i,nj=j;
		if(a[i][j]==1) nj+=b[i][j];
		else if(a[i][j]==2) nj-=b[i][j];
		else if(a[i][j]==3) ni-=b[i][j];
		else ni+=b[i][j];
		 
		if(ni<1||ni>n||nj<1||nj>m) 
		{
			g[id[i][j]]=-1;
			continue;
		}
		
		g[id[i][j]]=id[ni][nj];
		in[id[ni][nj]]++;
	}
	
	vector<int>vt(n*m+1,0);
	int f=0;
	for(int i=1;i<=n;i++)
	{
		if(!in[i])
		{
			int u=i;
			vector<int>v;
			while(u!=-1&&!vt[u])
			{
				vt[u]=1;
				v.push_back(u);
				u=g[u];
			}
			if(v.size()==n*m)
			{
				cout<<"Yes\n";
				return ;
			}
			f=1;
			break;
		}
	}
	
	if(!f)
	{
		int u=1;
		vector<int>v;
		while(u!=-1&&!vt[u])
		{
			vt[u]=1;
			v.push_back(u);
			u=g[u];
		}
		if(v.size()==n*m)
		{
			cout<<"Yes\n";
			return ;
		}
	}
	cout<<"No\n";
	
	
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int 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: 3556kb

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: 67ms
memory: 13936kb

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
No
No
Yes
Yes
No
Yes
No
Yes
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
Yes
Yes
No
Yes
No
No
No
Yes
Yes
No
Yes
No
Yes
No
Yes
No
No
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
No
No
Yes
No
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
No
Yes
...

result:

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