#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll i,j,c,t,x1,x2,y1,y2,q;
char ch;
string s,str;
ios::sync_with_stdio(false);
cin.tie(0);
cin>>t;
while(t--)
{
cin>>s;
cin>>x1>>y1;
cin>>q;
while(q--)
{
cin>>x2>>y2;
str="";c=0;
if(x1>x2)
ch='L';
else
ch='R';
for(i=0;i<abs(x1-x2);i++)
str+=ch;//creating the required subsequence
if(y1>y2)
ch='D';
else
ch='U';
for(i=0;i<abs(y1-y2);i++)
str+=ch;//here also creating the required subsequence
j=0;
for(i=0;i<str.length();i++)//checking if the subsequence is present in the string or not
{
while(j<s.length())
{
if(str[i]==s[j])
{
c++;j++;break;//maintaining the count c if every character of the subsequence is present or not in the string
}
j++;
}
}
if(c==str.length())
cout<<"YES "<<c<<"\n";
else
cout<<"NO\n";
}
}
}
I did the same thing but got wrong answer can anyone please tell me where I was wrong?
(There is no issue with uppercase lowercase yes no) https://www.codechef.com/viewsolution/37001346
I had wrongly interpreted the instructions, I was taking y1+1 for D instead for U. But after that I still received a TLE, I was using fast i/o and ‘\n’ but still was getting a TLE. After that instead of using an array for storing the character counts I switched to using 4 individual variables and then got accepted. Can anyone explain why I was getting a TLE with an array?
I ran my code using custom input same as given in the problem statement and it ran successfully.
But on submitting I was shown that my answer is wrong. Can anyone please help me out in finding out what went wrong in my code?? https://www.codechef.com/viewsolution/37020739
my code blocks ide is not showing output when i am using “\n” but showing output when i am using endl for this problem. But using “\n” gave me correct answer now when submitted ,can anyone help me rectify this.