I tried submitting a code for the problem 490B - Queue which displayed correct output for the sample case in codeblocks(ide that I use) with G++17 but it showed wrong answer on test 1(47521144), then I just changed the language to G++14 and it showed wrong answer on test 8(47521204) whereas test 8 was also working fine on my ide. Then I opened codeforces custom-test and got to see that I was getting different answers for C++17 than those of C++14 and C++11(11 and 14 were same). Then I changed my code a little bit(please see that change here: 47521514 ) and it gave correct answers for all the three languages on custom-test and I submitted it with G++17 and it got accepted(same as above). The problem I can see is : I was not assigning value as 0 to a key and value to a key 0(unordered map) and was making a while loop with terminating condition being till the time there is value for a key updating key every time to the value and it worked well on my ide(please see the codes above for better reference). Please tell why is this happening or what is the best practice or what to avoid in future.
Here you loop over a hash map while modifying it.
https://en.cppreference.com/w/cpp/container/unordered_map/operator_at:
I assume that if you insert zeros in advance, no modification is happening.
To avoid this, you could use std::map:
Thanks :)
I had the same issue today. Thanks for this blog post.
I had problem in this question https://mirror.codeforces.com/contest/1462/problem/E1