I approached this problem in 3 different ways and failed which led me to abandon the remainder of the contest in disappointment.I would really appreciate anybody who would go through the code and identify the loophole which I couldn’t identify despite days of scratching my head.

1st approach: Counting all valid subsequences till index i Code 1 P.S. Code comments are highly unindented on codechef IDE.

2nd approach: Eliminating invalid subsequences from total possible sequences.Code 2

3rd approach: Bruteforcing all valid subsequences and checking if they are valid. I completely understand the TLE for ST2 but why the WA in ST1 Task 3. That made me think the entire approach of multiple of 4 and odd numbers is not correct and I gave up.

Code 3

Really appreciate any sort of feedback. :slightly_smiling_face:

In C++, a negative number modulo a positive number may be negative. Not sure if that’s the only problem, but it’s definitely one.

That was the only issue thanks a lot. :smiley:

(-a) % b = b - (a%b)

Shouldn’t that be b - (a % b) on the right side?

1 Like