not waste completely!! That one hour taught you not to ignore such minor things written on question. It also increases your understanding of c++ that “endl” and “\n” are not same 
I had tried submitting in Python using sys library and “\n” and that was not working either. It worked on C++ with “\n” instead of endl.
that is not possible I have submitted the code and it passed all the test case look the code which i provided its yours only!!!
Caught this Block
ll R=0,L=0,U=0,D=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='R')
R++;
else if(s[i]=='L')
L++;
else if(s[i]=='U')
U++;
else if(s[i]=='D')
D++;
}
Bro you are recalculating L,U,D,R for every query in a test case ,
whereas these variable are fixed in each test case
You need to calculate them only once in each test case
if still unclear
position the above block before while(q–){ } block
@ajaysr Use “\n” instead of endl. “\n” is faster. I submitted your same code with “\n” and got AC CodeChef: Practical coding for everyone
think this if xdiff=0
then no matter what still else block in this code is going to execute (which was expected for xdif<0)
if(xdif>0){
if(xdif<=countR){
flag1=true;
ans1=(xdif);
}
}
else{
if(abs(xdif)<=countL){
flag1=true;
ans1=(abs(xdif));
}
}
Can ayone explain how the time complexity is calculated here??
try to use \n rather than endl.
because of endl i lost my rating now i will always use “\n”
Hello everyone,
I have used fast io as suggested but still I am getting TLE. Can anyone let me know the reason?
Thanks in Advance!!
I thought it diffrently as it was a reply ,lol. Anyways peace .
pls can someone tell me whats wrong with my code
#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";
}
}
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
IOS;
ll t; cin>>t;
string s; cin>>s;
ll r1 =0, l1=0,u1=0,d1=0;
for(int i=0;i<s.length();i++)
{
if(s[i]==‘L’) l1++;
if(s[i]==‘R’) r1++;
if(s[i]==‘U’) u1++;
if(s[i]==‘D’) d1++;
}
while(t–)
{
ll x,y,l,r,u,d; cin>>x>>y;
ll n;
cin>>n;
while(n--)
{
ll x1,y1; cin>>x1>>y1;
l =l1; r=r1; d=d1; u=u1;
ll diffx = x1 - x;//>r
ll diffy = y1 - y;//>u
if(diffx<0)
{
l+=diffx;
}
else if(diffx>0)
{
r-=diffx;
}
if(diffy>0)
{
u-=diffy;
}
else if(diffy<0)
{
d+=diffy;
}
if(l>=0 and r>=0 and u>=0 and d>=0)
{
cout<<"YES"<<" "<<abs(diffx)+abs(diffy)<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
}
}
What’s wrong with this?
Please help!
That works…
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
Consider the test input:
1
DDDD
1 2
1
1 3
thanks brother
I did the exact same thing but still got wrong answer.
https://www.codechef.com/viewsolution/37002865
Can you help me figure out what I missed …
Thank You
Consider the test input:
1
R
0 0
1
100 1
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?