You are not logged in. Please login at to post your questions!


Why i am getting WA?

Can someone tell me why i am getting WA?

My Program for Problem SEBIHWY

asked 21 Nov '16, 00:00

coder_voder's gravatar image

accept rate: 8%

edited 08 Dec '16, 17:25

admin's gravatar image

0★admin ♦♦

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.


answered 21 Nov '16, 00:22

todumanish's gravatar image

accept rate: 0%

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.

(21 Nov '16, 00:33) diveshuttam3★

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

(21 Nov '16, 00:45) todumanish4★

yes i did it's giving father only

(21 Nov '16, 00:49) diveshuttam3★

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.

(21 Nov '16, 11:42) diveshuttam3★

@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 <cmath> 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


answered 21 Nov '16, 01:51

diveshuttam's gravatar image

accept rate: 27%

edited 21 Nov '16, 13:02


answered 21 Nov '16, 00:03

diveshuttam's gravatar image

accept rate: 27%

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

(21 Nov '16, 00:05) coder_voder2★

What's wrong in my code?



answered 21 Nov '16, 00:15

ghamandipp's gravatar image

accept rate: 0%

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.


answered 21 Nov '16, 02:52

g123's gravatar image

accept rate: 0%

edited 21 Nov '16, 03:03

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.

(21 Nov '16, 11:37) diveshuttam3★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 21 Nov '16, 00:00

question was seen: 1,162 times

last updated: 08 Dec '16, 17:25