The minimum cost
Practice
3.9 (30 votes)
Bit manipulation
Basic programming
Basics of bit manipulation
Problem
60% Success 6912 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a binary array (array consists of \(0's\) and \(1's\)) \(A\) that contains \(N\) elements. You can perform the following operation as many time as you like:

  1.  Choose any index  \(1\leq i \leq N\) and if it is currently 0, then convert it to 1 for C01 coins.
  2.  Choose any index  \(1\leq i \leq N\) and if it is currently 1, then convert it to 0 for C10 coins.

Your task is to transform the given array into a special array that for every index \(1 \leq i < N\), \(A_i \land A_{i+1} = 1\).

Here, \(\land\) denotes XOR.

Input format

  • The first line contains \(T\) the number of test cases.
  • The first line of each test case contains three space-separated integers \(N\), C01 and C10.
  • The second line consists of \(N\) space-separated integers of array \(A\).

Output format

For each test case, print one line denoting the minimum cost to transform array \(A\) into a special array.

Constraints

\(1 \leq T \leq 100\)

\(1 \leq N \leq 10000\)

\(0 \leq A[i] \leq 1 \forall i \in [1,N]\)

\(1 \leq C01,C10 \leq 1e9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
56 votes
Tags:
ApprovedBasic ProgrammingBit manipulationEasyOpen
Points:20
2 votes
Tags:
Bit ManipulationBasics of Bit ManipulationBasic Programming
Points:20
14 votes
Tags:
Bit manipulationBit ManipulationBasics of Bit ManipulationBasic Programming