Chef And Division CodeChef Solution | CodeChef Problem Solution 2022
You are given an array of size .
A partitioning of the array is the splitting of into one or more non-empty contiguous subarrays such that each element of belongs to exactly one of these subarrays.
Find the number of ways to partition such that the parity of the sum of elements within the subarrays is alternating. In other words, if denotes the sum of the elements in the -th subarray, then either
- is odd, is even, is odd and so on.
- or is even, is odd, is even and so on.
For example if . One way to partition is . Another way to partition is . Note that there exists more ways to partition this array.
Solution Click Below:-
Since the answer may be large, output it modulo .
Input Format
- The first line contains a single integer - the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer - the size of the array .
- The second line of each test case contains space-separated integers denoting the array .
Output Format
For each test case, output the answer modulo .
Constraints
- Sum of over all test cases does not exceed
Sample Input 1
3
3
1 2 3
4
4 4 4 4
5
1 2 3 3 5
Sample Output 1
2
1
5
Explanation
Test case 1: The array can be partitioned as follows
Test case 2: The array can be partitioned as follows
No comments:
Post a Comment