Lelouch.Lamperouge's blog

By Lelouch.Lamperouge, history, 4 years ago, In English

Hi, I was trying to solve the problem Traffic Lights from codeforces round 29 I was able to solve the problem but can somebody explain how just changing the language from C++14 to C++17 causes a change in the verdict
Wrong Answer Solution
Accepted Solution

»
4 years ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

float/double are not precise, they usually don't give accurate results.

You can even try that yourself on CUSTOM INVOCATION on codeforces,

double x=(double)1/1001 now output x and x*1001, now x*1001=0.9999.... & not 1, happens because the value stored in x is not exactly 1/1001 (rather a value very close to that)

And now coming to your solution, it passed on C++17 by luck :)

You can try your code in CUSTOM INVOCATION on C++17, just output c after you have done c=c-floor(c), now on both C++14/C++17 your final answer will be 2 and not 1002