QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#349997#6723. Grid with Arrowswudibaolong#RE 0ms3620kbC++142.1kb2024-03-10 11:38:402024-03-10 11:38:40

Judging History

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

  • [2024-03-10 11:38:40]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3620kb
  • [2024-03-10 11:38:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define endl '\n'
int G[N];
int du[N];
char arrow[N];
int val[N];
int st[N];
int find_set(int x)
{
	if(st[x] != x) st[x] = find_set(st[x]);
	return st[x];
}
void union_set(int a,int b)
{
	int fa=find_set(a),fb=find_set(b);
	st[fa] = fb;	
}

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		scanf("%d %d",&n,&m);
		
		
		for(int i=0;i<n*m;i++) st[i]=i;
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				char ch;
				scanf(" %c",&ch);
				arrow[i*m+j]=ch;
			}
		}
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				int num;
				scanf("%d",&num);
				val[i*m+j]=num;
			}
		}
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arrow[i*m+j] == 'u')  
				{
					int num=(i-val[i*m +j])*m +j; 
					G[i*m + j] = num;
					
					du[i*m+j]++;
					du[num]--;
					
					union_set(i*m+j,num);
				}
				else if(arrow[i*m+j] == 'd')  
				{
					int num=(i+val[i*m +j])*m +j; 
					G[i*m + j] = num;
					du[i*m+j]++;
					du[num]--;
					union_set(i*m+j,num);
				}
				else if(arrow[i*m+j] == 'l')  
				{
					int num=i*m +j-val[i*m +j]; 
					G[i*m + j] = num;
					du[i*m+j]++;
					du[num]--;
					union_set(i*m+j,num);
				}
				else if(arrow[i*m+j] == 'r')  
				{
					int num=i*m +j+val[i*m +j];  
					G[i*m + j] = num;
					du[i*m+j]++;
					du[num]--;
					union_set(i*m+j,num);
				}
			}
		}
		bool flag=1;
		int root=find_set(0);
		for(int i=0;i<n*m;i++) 
			if(find_set(i) != root) flag=0;
		
		if(!flag)
		{
			cout<<"No"<<endl;
//			cout<<"未联通"<<endl; 
//			for(int i=0;i<n*m;i++)
//			{
//				
//				cout<<i<<" "<<G[i]<<" "<<endl;
//				cout<<arrow[i]<<" "<<val[i]<<endl;
//			}
			continue;
		}
		
		int cnt_1 = 0, cnt1=0;
		for(int i=0;i<n*m;i++) 
		{
			if(du[i] == -1) cnt_1++;
			if(du[i] == 1) cnt1++;
		}
		if(cnt_1 == 1 && cnt1 == 1)
		{
			cout<<"Yes"<<endl;
		}
		else if(cnt_1 == 0 && cnt1 == 0)
		{
			cout<<"Yes"<<endl;
		}
		else cout<<"No"<<endl;
	}
	
	
 } 

詳細信息

Test #1:

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

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:


result: