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

Автор elamharnish, история, 17 месяцев назад, По-английски

In a Codeforces Round 880 contest in the problem C (Div. 2) (or A Div. 1) I have got a time limit when I used C++17 (submission: https://codeforces.net/contest/1836/submission/210134408) and have got AC using C++20 (https://codeforces.net/contest/1836/submission/210135600) with exactly the same code. Of course my solution was not optimal (I used binary search), but my question to the community is why C++20 submission is faster? Is it a general fact, and hence it is better to use it further? Thank you for answering.

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

»
17 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Yes I'm quite sure c++20 is almost always faster. Not only that, there are many cases where unordered map blew up in c++17 but didn't in c++20. So i think its safer as well.

»
17 месяцев назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

Again, it's not about standard. It's about compiler

C++17 generate 32bit words machine code, c++20 (64bit) generates 64bit words machine code. So long long variable (which has in both compilers 64bits) need 2 registers for first compiler and 1 register for second.

So nothing strange that if you get rid of unnecessary long long operations you get AC in both compilers.
210531038

Yes, still slower than C++20 (64bit) but it is because C++20 (64bit) can store two int32_t variables in one register and do two operations at once.