SEBIHWY - Editorial

Please anyone help me out to find the error, it was showing WA CodeChef: Practical coding for everyone

can anyone please say why is it showing WA :frowning: CodeChef: Practical coding for everyone

I hope this will answer a some of you getting wrong answer. I had the same problem as most of the guys here. Getting wrong answer when I checked it like a thousand times. Finally during the last half an hour I tried something without any hope of it working but it fetched me AC. What I did was to first check for “DRAW” that is the equals condition rather than “FATHER” or “SEBI” and that is it.

adding a point the answer of @iscsi it is not the matter of float here. As below is @qruiger_116 's solution with using float. Got ac by just changing the expression .so in general float and double are the cause of such problems; it is not so here. Check this out CodeChef: Practical coding for everyone
here the point is that you may lose precisision by dividing first as no. of decimal points is fixed. For more details check the links in my answer below

https://www.codechef.com/viewsolution/12247224
kindly tell me what is wrong in this ans

@hs_123 the distance between the two cars in km can be in decimal, example: 1500 metres=1.5 km. Please read the editorial, it is explicitly mentioned to use typecasting or declare as float or double.Anyway, I changed the datatype to float and used fabs instead of abs in your code and got AC. This is the link to your updated code.
https://www.codechef.com/viewsolution/12272086

whats wrong in this

#include <iostream>
#include<stdlib.h>
using namespace std;

int main() {
  
  double t1,s1,s2,d,t,s;
  double a;
  std::cin>>t1;
  t1--;
  do{
    std::cin>>s>>s1>>s2>>d>>t;
    
      a=d*3.6*50/t;
      a=a+s;
      if(abs(a-s1)<abs(a-s2))
      std::cout<<"SEBI"<<endl;
      if(abs(a-s1)>abs(a-s2))
      std::cout<<"FATHER"<<endl;
      if(abs(a-s1)==abs(a-s2))
      std::cout<<"DRAW"<<endl;
      
  }while(t1--);
  
  
	// your code goes here
	return 0;
}

#include
#include <bits/stdc++.h>
using namespace std;

int main() {
double tc,s,sg,fg,d,t;
double sp=0.00,d1=0.00,t1=0.00;
cin>>tc;
while(tc–)
{
cin>>s>>sg>>fg>>d>>t;
d1=(double)(d50/1000); //distance in km
t1=(double)(t/60); //time in min
sp=(double)(d1
60/t1); //actual speed of other car

    sp=(double)(sp+s);
  if((abs)(sg-sp)==(abs)(fg-sp))
  cout<<"DRAW"<<endl;
    else if((abs)(sg-sp)<(abs)(fg-sp))
    cout<<"SEBI"<<endl;
    else 
    cout<<"FATHER"<<endl;
}
return 0;

}
please tell me what is wrong in this code?..Its giving me wrong answer

//here is simple C++ code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int s,sg,fg,d,T;
cin>>s>>sg>>fg>>d>>T;
if(sg==fg)
cout<<“DRAW”<<endl;
else
{
float dis=50d;
float v=(dis
6060)/(1000T);
v+=s;
if(fabs(v-sg)<fabs(v-fg))
cout<<“SEBI”<<endl;
else if(fabs(v-sg)>fabs(v-fg))
cout<<“FATHER”<<endl;
else
cout<<“DRAW”<<endl;
}
}
return 0;
}

Can someone please tell me what is wrong. Tried many test cases and works for all but still getting wrong answer
https://www.codechef.com/viewsolution/12641292

@rchandu

I had a look at your code and found this

		 "System.out.println(speed);"

The output CLEARLY says to print only “SEBI” or “FATHER” or “DRAW”

If you print out ANYTHING ELSE, like speed etc. Then the online judge (which is NOT a human) will flag your answer as wrong result. Follow output format closely, as even an extra blank space or full stop or comma will get you a wrong answer

Hope it helps :slight_smile:

Can someone help me here? What is missing in my code? I am getting a WA.
https://www.codechef.com/viewsolution/15176177

Can someone tell me why I’m getting a WA? :frowning: :frowning:

https://www.codechef.com/viewsolution/12127964

using std::abs might help see my ans below for detail.

https://discuss.codechef.com/questions/87910/sebihwy-editorial/87954

try using the expression given in the editorial.for details my ans below.

try using fabs. and simplifying the expression

but, it’s the same thing, the expression given in the editorial is just more simplified than what I’ve written, it should give AC in both the cases. Still can’t figure out where I went wrong…

please read the ans below when you divide first you lose precision as there are only say 19 digits after the decimal. Moreover expression d/1000/tx50x3600 yields wrong ans but dx3600x50/t/1000 yields right answer. You should check the links in my answer. I tried almost 40 diff. solutions to check this out.

So lets look this sample with your code

1
7 213 221 7 6

int this case the other car sped is 217, your solution calculates with floats

the other car speed is in your code oc = 216.99998

diff1 : 3.9999847
diff2 : 4.0000153

if I change the floats to double in your code : oc will be = 216.99999999999997

diff1: 3.9999999999999716
diff2 : 4.0000000000000284

so you can see it also contains precision error.

Of course you can correct your solution if ABS(diff1 - diff2) < epsilon it should be consider equal. For your solution e.g. epsilon=1e-7 would be a sufficient.

1 Like

Ohkay. Thank you @diveshuttam and @iscsi for your explanations. Much Appreciated.