XORSUB problem

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

https://www.codechef.com/viewsolution/8884014

whereas AC when declared in main :

https://www.codechef.com/viewsolution/8884063

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.

2 Likes

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)

vs

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
//