QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350029#6723. Grid with Arrowswudibaolong#AC ✓56ms10000kbC++141.6kb2024-03-10 12:51:452024-03-10 12:51:46

Judging History

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

  • [2024-03-10 12:51:46]
  • 评测
  • 测评结果:AC
  • 用时:56ms
  • 内存:10000kb
  • [2024-03-10 12:51:45]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>
#include<queue>
#define ll long long
const int N=1e6+10;
const ll mod=1e9+7;
ll read(){
    ll s = 0, f = 1; char ch = getchar();
    while(!isdigit(ch)){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return s * f;
}
using namespace std;
char s[N];
int sum,n,m;
int fa[N],ru[N];
int find(int x){
	return x==fa[x]? x:fa[x]=find(fa[x]);
}
void merge(int x,int y){
	int u=find(x);
	int v=find(y);
	if(u!=v){
		fa[v]=u;
	}
}
void init(){
	sum=n*m;
	for(int i=1;i<=sum;i++) fa[i]=i,ru[i]=0;
	return ;
}
int locate(char ch,int i,int j,int u,int ans){
	int v=0;
	if(ch=='u'&&i-ans>=1)
		v=u-ans*m;
	if(ch=='d'&&i+ans<=n)
	    v=u+ans*m;
	if(ch=='l'&&j-ans>=1)
	   v=u-ans;
	if(ch=='r'&&j+ans<=m)
	   v=u+ans;
	return v;
}
void solve(){
	n=read();m=read();
	init();
	for(int i=1;i<=n;i++)
	 for(int j=1;j<=m;j++){
	 	cin>>s[(i-1)*m+j];
	 }
	 //for(int i=1;i<=sum;i++) cout<<s[i];
	 int ans,u,v;
	 for(int i=1;i<=n;i++){
	 	for(int j=1;j<=m;j++){
	 		ans=read();
	 		u=(i-1)*m+j;
	 		v=locate(s[u],i,j,u,ans);
	 		if(v){
	 		merge(u,v);
	 		ru[v]++;
			}
		 }
	 }
	 int f=find(1);
	 for(int i=2;i<=sum;i++){
	 	if(find(i)!=f){
	 		cout<<"No"<<endl;
	 		return;
		 }
	 }
	 ans=0;
	 for(int i=1;i<=sum;i++){
	 	if(ru[i]==0) ans++;
		if(ans>=2) {cout<<"No"<<endl;return ;} 
	 }
	 cout<<"Yes"<<endl;
	 return ;
}
int main (){
	int T;cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7792kb

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: 0
Accepted
time: 56ms
memory: 10000kb

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

result:

ok 1109 token(s): yes count is 602, no count is 507