Leif_Erikson's blog

By Leif_Erikson, history, 7 weeks ago, In English

Hello, Codeforces.

I've sent different submissions with same code with different compilers on problem Burenka Plays with Fractions from last round and got different results.

I would've gotten a higher rate if this strange thing hadn't happened.

Strange that I get wrong answer with modern compilers and accepted with old compilers !

Can anyone explain that ?!

  • Vote: I like it
  • -11
  • Vote: I do not like it

7 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Likely, your code had an usage of what is known as Undefined behaviour. If this is the case, then we are unable to know, let alone guarantee, if your code works as expected in every compilation environment. You need to be cautious of these situations!

7 weeks ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

It is never a good idea to directly compare floating-point numbers using the equality comparison operator.
As per why the results were different, the C++ standard isn't very stringent about what the extra digits should be after the minimum precision (about 16 digits for double), i.e., they are implementation-defined. The test-case on which your code gave the wrong answer (expected output : 2), your code's output was 0, because double may not have been precise enough to differentiate between 1000000000/999999999 and 999999999/999999998 in one compiler and was in the other.

7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

You shouldn't compare floating-point values using the == operator.

I resubmit your WA 13 C++17 (64) solution and get AC by turning on excess precision, but I wouldn't recommend relying on this method to get AC though.