Please read the new rule regarding the restriction on the use of AI tools. ×

sany11053's blog

By sany11053, 17 months ago, In English

In the recent contest Educational Codeforces Round 147 (Rated for Div. 2), Question C. I faced ambiguity when compiling my code with GNU G++17 7.3.0. Here is my submitted code 202889532 and 202887839

When line 35, which is an output statement, is commented out. I get different return value

If I print an empty string "", my return value, and hence output changes.

Please have a look! MikeMirzayanov

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

| Write comment?
»
17 months ago, # |
  Vote: I like it +21 Vote: I do not like it

It's NEVER the compiler's fault.

  • »
    »
    17 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    there are some extremely rare documented exceptions to this general rule

  • »
    »
    17 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you help me troubleshoot the problem?

    • »
      »
      »
      17 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It could be a double precision error. Try calculating $$$\log_2 x$$$ using integers only. In your example $$$m = 8$$$, so my guess is, that $$$log_2 8$$$ will be something like $$$2.9999 \ldots$$$, instead of $$$3$$$, and it gets rounded down to $$$2$$$.

»
17 months ago, # |
  Vote: I like it +13 Vote: I do not like it

Seems to be a case of excess precision. The difference between the two cases might be that the call to cout can fail (or have some other side-effect) that forces the compiler to not optimize away the store to t.

However this still doesn't guarantee that your code will AC — even if the underlying logic is correct, the division of the logs seems quite unreliable.