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.net/contest/1768/submission/188128207 G++ 17: https://codeforces.net/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?
I hope someday there will be hint on topic creation like "if you have strange results in different compilers then vveeeeeeerrryyyyy most likely you've got undefined behaviour and examples of it"
There is no
dual[n]
, so it seems that arraya
is allocated right after arraydual
, sodual[n]
is reference toa[0]
actually.You got ac out of luck. Main problem is you are accessing nth idx where dual have a size of n. Just increase the dual array size.