Блог пользователя pritishn

Автор pritishn, история, 4 года назад, По-английски

One of my friends noticed a strange behaviour of .size() method.

Link to WA submission : https://codeforces.com/contest/1307/submission/88824759
Link to AC submission : https://codeforces.com/contest/1307/submission/88824749

The bug is in the line
LL x=a[i].size()*(a[i].size()-1)/2;

In C++17 , I guess there is overflow in that expression.
But in C++17(64) , it works fine.

So does that mean the .size() operator can hold larger numbers in 64bit version?
And also what other methods show this kind of varying behaviour when the compiler changes from 32bit to 64bit??
Can anyone explain this please??

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +19 Проголосовать: не нравится

So does that mean the .size() operator can hold larger numbers in 64bit version?

Yes. The return value of .size() is a std::size_t. And the standard only guarantees that it is at least 16 bits long. In practice, on a 32 bit system it will be 32 bits, and on a 64 bit system it will be a 64 bit integer.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Thanks for confirming. :)

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    Similar things happen with other integer types as well. For instance the C++ standard only guarantees that a long integer has at least 32 bits. On a modern Linux system with gcc it will be 32 bits, like an int, but on Windows with Visual Studio it will actually be 64 bits, like a long long.