-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelp Martha.cpp
More file actions
100 lines (82 loc) · 1.7 KB
/
Help Martha.cpp
File metadata and controls
100 lines (82 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// /Code by : Harry_Singh/
#include<bits/stdc++.h>
#define int long long int
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n"
#define br break
#define N 10005
// directions
int xx[5]={0,0,1,-1};
int yy[5]={1,-1,0,0};
vector<int > G[N],L[N];
void we_have_choices()
{
string s;
cin>>s;
int x,y;
cin>>x>>y;
int q;
cin>>q;
int l=0,r=0,u=0,d=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='R')r++;
else if(s[i]=='L')l++;
else if(s[i]=='D') d++;
else u++;
}
while(q--)
{
int a,b;
cin>>a>>b;
int flag=1;
int c=0;
if(a>=x)
{
int ans=a-x;
if(r>=ans)c+=ans;
else flag=0;
}
if(a<x)
{
int ans=x-a;
if(l>=ans)c+=ans;
else flag=0;
}
if(b>=y)
{
int ans=b-y;
if(u>=ans)c+=ans;
else flag=0;
}
if(b<y)
{
int ans=y-b;
if(d>=ans)c+=ans;
else flag=0;
}
if(!flag)cout<<"NO";
else cout<<"YES "<<c;
tr;
}
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
io;
int t;cin>>t;
while (t--)we_have_choices();
return 0;
}