XORSUB problem

Can somebody explain why I got WA when declared the array “dp” outside main in this solution:


whereas AC when declared in main :


The only difference in the two solutions is only the position of declaration of the array. I was also initialising the array to 0 for each test case.


Outside the main it’s static nd inside its dynamic. Always declare large arrays outside main and re-use it.

I think you are not setting dp array to zero after the test case loop!

It’s actually not the only difference (use diff - there’s array size difference and one expression difference).
It’s about the

if((i^k) > max)


if(i^k > max)

which is the same as

if(i^(k > max))

C just let you shoot yourself in the leg :wink:

1 Like