QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#350027 | #6723. Grid with Arrows | wudibaolong# | WA | 89ms | 4644kb | C++14 | 2.0kb | 2024-03-10 12:51:23 | 2024-03-10 12:51:24 |
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;
for(int i=0;i<n*m;i++)
{
if(find_set(i) != root) flag=0;
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(cnt1 <= 1 and cnt_1 <= 1)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3684kb
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: 89ms
memory: 4644kb
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 No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [5th token]