×

# Why i am getting WA?

 0 Can someone tell me why i am getting WA? asked 21 Nov '16, 00:00 593●3●31 accept rate: 8% 0★admin ♦♦ 19.7k●350●498●541

 2 @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  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 537●1●8 accept rate: 27%
 0 check out the editorial https://discuss.codechef.com/questions/87910/sebihwy-editorial answered 21 Nov '16, 00:03 537●1●8 accept rate: 27% Thanks but can you figure out whats wrong in my code. (21 Nov '16, 00:05)
 0 What's wrong in my code? answered 21 Nov '16, 00:15 1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×2,698
×11

question asked: 21 Nov '16, 00:00

question was seen: 1,162 times

last updated: 08 Dec '16, 17:25