I am getting TLE in the third subtask. How to avoid/correct this?
Why are u using two loops for checking even and odd
Ans also put condition before loop for n=1 and n=2
@venkat_asuri if you understand the problem statement we need to find out the no. of pairs such that their sum is odd.
And we know,
even + even = even
odd + odd = even
odd + even = odd
So what we need to do is to count the total no. of odds in the array and total no. of evens and then multiply them to get the answer.
Answer = (Total odds in arr)*(Total evens in arr)
long long int a[n],i,o=0,e=0;
Here is the solution… Solution: 40721945 | CodeChef
In this question we can do it in two ways -
i) using two for loop which will give us TLE
ii) Using one for loop. In this we will count number of even and odd number in the array and use permutations and odd number property.
Odd number property - even + odd = odd
so we have to choose one even and one odd number we use premutation = number of even * number of odd