Why i am getting WA?

Can someone tell me why i am getting WA?

My Program for Problem SEBIHWY

check out the editorial https://discuss.codechef.com/questions/87910/sebihwy-editorial

Thanks but can you figure out whats wrong in my code.

What’s wrong in my code?

link: https://www.codechef.com/viewsolution/12127528

use function fabs instead of abs because abs is for integer and fabs is for double and fabsf is for float. and your code is giving wrong answer for this simple test case
1
1 19 19.5 1 2
your code is giving output draw but answer must be Father.

1 Like

No it is giving father only as what you are saying applies to c. But in c++ both are same.Tried the code.Feel some problem with precision.

I think you should run this code in your pc and test for above test case and check the answer.

yes i did it’s giving father only

@all Alright the question is really interesting a cakewalk that makes you realize that there is difference between real life and computer world;In real world we have infinite precision of floats. But not so in computer I had seen a cs50 video which talks about this 2 months back i didn’t know that it would come this handy though i was not able to find the video you can check this link and this link.The editorial also mentions this part when they say (Be careful: This speed isn’t necessarily an integer). Though the question mentions of converting to double carefully will give AC but i don’t think so moreover the setter’s solution compares distances(integers) rather than speed.Now interesting part about integers is that they are precise.
I hope that this is only the reason ; still trying to get it work the old way as some solutions of others in c work that way.will update this answer soon.

Update : so yes i was partially correct;Had a nice time figuring all the stuff you can see my solutions here.
So there are two mistakes in your solution:

  1. you have divided t/3600 first and lost the precision(significant value of the time).so instead of that using t=t/3600 use d*3600 first as instead of using d/1000/t*3600*50 using d*3600*50/1000/t changed WA to AC for me.Though best is to use d*180/t
  2. use std::abs instead of abs as it seems as if there are two abs function 1 defined in namespace std which is overloaded for double and one in only for integers. Since c headers don’t use namespaces so abs referred here is probably the cmath one which is not compatible.Though i got correct answers for the floats that i tried at my computer as suggested by @todumanish but this is not true for codechef as just adding std::abs gave the right answer. It might be dependent on compiler maybe. PS. A disadvantage of using <bits.stdc++.h>
    other way is to compare distances rather than speed

EDIT: the definition of abs() is still not clear but for sure there are two abs one with the float optimization(std::abs) one without it.Not sure about there libraries. The implementation seems compiler dependent as found through this post on stackoverflow

1 Like

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.

you made many changes to your code it was not checking == first rather changing the way to calculate your answer that helped.I tried various versions of your solution removing all the typecasting, changing the sequence of if all gave AC untill i changed the expression itself.BTW your solution helped a lot in figuring out the details.

alright your point was also correct this case gave same ans on my pc but yes it might not have have given correct ans on codechef. instead of abs it should be std::abs.Thanks your point helped in figuring it all.