Why is thIS CORRECT solution getting WA for GMEDIAN?

This is my solution which only got 5 points,I did everything right, then why I did not get 30 points? I used the Fermat Modulo Theorem to calculate (n C r) % p :- CodeChef: Practical coding for everyone

1 Like

Your solution is passing only the first sub-task because it is computing the good subsequence of even length incorrectly. (There are no duplicates in the first sub-task, hence the number of good subsequence of even length is zero).

Here’s a test case on which your program is failing.

1

5

1 2 2 2 3

The correct answer should be (16+8) 24, but your program falsely returns the answer as (16+6) 22.

Here’s my implementation (In case you want to compare your output on custom inputs).

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

1 Like

Let a1=1;
a2=2;
a3=2;
a4=2;
a5=5;

The good even subsequences are:- {2,2}
{2,2}
{1,2,2,3}
{1,2,2,2}
{1,2,2,3}
{2,2,2,3}

Which are the other two I am missing ?

One of them I found out is : - {a1,a2,a4,a5}

Which is the other one I missed?
Oh, I got it, its, {a2,a4};
Thankyou,verymuch!