Even Array
Practice
2.9 (10 votes)
Introduction to dynamic programming 1
Algorithms
Dynamic programming
Bit manipulation
Problem
40% Success 1572 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
An array is called good if every element of the array is an even integer.
You are given an array A of length N. In one move, you can do one of the following operations:
- Choose an index i and set \(A_i =\lfloor \frac{A_i}{2} \rfloor\)
- Choose an index \(1 \le i \lt \mid A\mid\)and replace \(A_i, A_{i+1}\) with one occurrence of \(A_i \oplus A_{i+1}\). Here \(\mid A \mid\) denotes the length of the array A and \(\oplus\) denotes bitwise XOR operation.
Find the minimum number of moves needed to make array A good.
Input format
- The first line contains T denoting the number of test cases. The description of T test cases is as follows:
- For each test case:
- The first line contains N denoting the size of array A.
- The second line contains N space-separated integers \(A_1, A_2, \dots, A_N\) - denoting the elements of A.
Output format
For each test case, print the minimum number of moves needed to make array A good.
Constraints
\(1 \leq T \leq 10^4 \\ 2 \leq N \leq 10^5\\ \\1\leq A_i \lt 2 ^{30} \\ Sum\; of \; N\;over\;all\;test\;cases\;does\;not\;exceed\;2\cdot 10^5. \)
Submissions
Please login to view your submissions
Similar Problems
Points:50
7 votes
Tags:
AlgorithmsDynamic ProgrammingIntroduction to Dynamic Programming 1
Points:50
8 votes
Tags:
Introduction to Dynamic Programming 1AlgorithmsDynamic Programming
Points:50
5 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingGrammar-VerifiedHardHiringRecruit
Editorial