Weird behaviour with GNU G++ 20

Revision en1, by TheBhediyaOfDalalStreet, 2023-01-05 21:05:50

Pardon my choice for variable naming (I was projecting), but I fail to understand why the same code gives me WA with G++20 but AC with G++17

G++20: https://codeforces.me/contest/1768/submission/188128207 G++ 17: https://codeforces.me/contest/1768/submission/188129998

Further, on debugging with G++20 for the case:

1
2
2 2

I found that mysteriously, a[0] becomes equal to 1 after the following for loop from the code is executed:

        for(int i = 1; i <= n; i ++) {
           if(cnt[i] > 2) {
                pos = 0;
                break;
            }
            if(cnt[i] == 2) {
                if(no_bitches.empty() || *no_bitches.begin() > i) {
                    pos = 0;
                    break;
                }
                dual[i] = *no_bitches.begin();
                no_bitches.erase(no_bitches.begin());
            }
        }

You can try it on custom invocation too. I don't change the input array a after taking in input, so I don't know how that happens... Can anyone explain?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English TheBhediyaOfDalalStreet 2023-01-05 21:05:50 1103 Initial revision (published)