Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

Amo_Woo_Jiho's blog

By Amo_Woo_Jiho, history, 3 months ago, In English,

955C - Sad powers in this problem a very strange behavior of compiler had happened and i didn't understand why ?? :|

  1. 43417754
  2. 43417574
  3. 43414929

In the above submission links you can see that first one is submitted in GNU C++14 and second one is submitted in GNU C++17 and third one submitted in GNU C++11. But unfortunately first one got WA and second one got AC. 3rd submission also got WA but same code. can anyone tell me why this happened ?
Thanks.

 
 
 
 
  • Vote: I like it  
  • +5
  • Vote: I do not like it  

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

That's because of builtin sqrt() function you are using. Try writing your own sqrt() function & see that your code gets Accepted in C++11 , C++14 & C++17

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

    why does this code work then? literally the same thing, just the variables changed.

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

      That's "undefined" behaviour u know !!

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

      sqrt() might give something slightly less than the actual square root (because of double precision) and converting it to long long would truncate the double(making the answer wrong by 1). So, you should add something like 0.01 before converting to long long.

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

      43416957 43416933 Spot The Difference (HARD)