GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 22 April 2022

Chef And Division CodeChef Solution | CodeChef Problem Solution 2022 

You are given an array A of size N.

A partitioning of the array A is the splitting of A into one or more non-empty contiguous subarrays such that each element of A belongs to exactly one of these subarrays.

Find the number of ways to partition A such that the parity of the sum of elements within the subarrays is alternating. In other words, if Si denotes the sum of the elements in the i-th subarray, then either

  • S1 is odd, S2 is even, S3 is odd and so on.
  • or S1 is even, S2 is odd, S3 is even and so on.

For example if A=[1,2,3,3,5]. One way to partition A is [1,2][3,3][5]. Another way to partition A is [1][2][3][3,5]. Note that there exists more ways to partition this array.

Solution Click Below:- 

Since the answer may be large, output it modulo 998244353.

Input Format

  • The first line contains a single integer T - the number of test cases. Then the test cases follow.
  • The first line of each test case contains an integer N - the size of the array A.
  • The second line of each test case contains N space-separated integers A1,A2,,AN denoting the array A.

Output Format

For each test case, output the answer modulo 998244353.

Constraints

  • 1T10000
  • 1N2105
  • 0Ai109
  • Sum of N over all test cases does not exceed 2105

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

  • [1][2][3]
  • [1,2,3]

Test case 2: The array can be partitioned as follows

No comments:

Post a Comment