C++17 Undefined Behavior

Revision en1, by Atomsky, 2021-06-21 05:38:23

In CF Round #727 (Div. 2), I submitted 120147862 for Problem-C: Stable Groups. It gave a wrong result on test 62 in GNU C++17. When I submitted the same code in GNU C++11, it was accepted (120149347).

I tried to figure out what went wrong in C++17. If I simply add a line that prints out the array output after line 14, like cout << foo[i] << endl;, the code gives the correct result in C++17. I am having trouble understanding why this might happen! What can I do in such cases?

Tags gnu c++17 vs gnu c++11

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Atomsky 2021-06-21 05:38:23 534 Initial revision (published)