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.me/contest/1836/submission/210134408) and have got AC using C++20 (https://codeforces.me/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.
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.
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.
Thank you, very clear now.