QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#350031 | #6723. Grid with Arrows | wudibaolong# | WA | 0ms | 3668kb | C++14 | 2.0kb | 2024-03-10 12:54:37 | 2024-03-10 12:54:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define endl '\n'
int du[N];
char arrow[N];
int st[N];
int n,m;
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;
}
bool check(int x,int y)
{
if(x <0 || x>=n) return 0;
if(y <0 || y>=m) return 0;
return 1;
}
int main()
{
int T;
cin>>T;
while(T--)
{
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 val;
scanf("%d",&val);
if(arrow[i*m+j] == 'u')
{
int num=(i-val)*m +j;
int x=i-val,y=j;
if(!check(x,y)) continue;
du[i*m+j]++;
//du[num]--;
union_set(i*m+j,num);
}
else if(arrow[i*m+j] == 'd')
{
int num=(i+val)*m +j;
int x=i+val,y=j;
if(!check(x,y)) continue;
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;
int x=i,y=j-val;
if(!check(x,y)) continue;
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;
int x=i,y=j+val;
if(!check(x,y)) continue;
du[i*m+j]++;
//du[num]--;
union_set(i*m+j,num);
}
}
}
bool flag=1;
int root=find_set(0);
int cnt_1 = 0, cnt1 = 0;
int cnt0;
for(int i=0;i<n*m;i++)
{
if(find_set(i) != root) flag=0;
if(du[i] == 0) cnt0++;
if(du[i] == -1) cnt_1++;
else if(du[i] == 1) cnt1++;
else if(du[i] !=0) flag=0;
}
//cout<<endl;
if(!flag)
{
cout<<"No"<<endl;
continue;
}
if(cnt0 < 2 )
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3668kb
input:
2 2 3 rdd url 2 1 1 1 1 2 2 2 rr rr 1 1 1 1
output:
No No
result:
wrong answer expected YES, found NO [1st token]