#P17129. [ICPC 2025 Shanghai R] Round screws

    ID: 19466 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>动态规划 DP贪心2025上海动态规划优化位运算ICPC根号分治折半搜索 meet in the middle

[ICPC 2025 Shanghai R] Round screws

Problem Description

The NIT likes round screws. He also likes the \oplus operator because it reminds him of round screws, where \oplus represents Bitwise-XOR operation.

Define the value VaV_a of a sequence a1,a2,,ana_1, a_2, \cdots, a_n as $V_a = a_1 + a_n + \sum_{i=1}^{n-1} (a_i \oplus a_{i+1})$.

Given a sequence a1,a2,,ana_1, a_2, \cdots, a_n, you can perform the following operation for arbitrary times:

  • Select an index ii (1in1 \le i \le n), change aia_i to any non-negative integer; this operation has a cost CC.

Minimize the sum of the value of the sequence and the cost incurred by operations. In other words, let pp be the number of operations you performed, and VaV_{a'} be the value of the aa after the operations, then you need to minimize pC+VapC + V_{a'}.

Input Format

The input contains multiple testcases. The first line of the input contains an integer TT (1T1001 \le T \le 100), the number of testcases.

For each testcase, the first line contains two integers n,Cn, C (2n105,0C<2192 \le n \le 10^5, 0 \le C < 2^{19}), the length of the sequence and the cost of performing an operation.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai<2180 \le a_i < 2^{18}), representing the elements in the sequence.

It’s guaranteed that the sum of nn over all testcases does not exceed 2×1052 \times 10^5.

Output Format

For each testcase, print an integer in 11 line, the minimum possible value of pC+VapC + V_{a'}.

3
4 4
1 4 5 6
8 6
6 6 6 1 1 6 6 6
6 7
1 7 2 6 3 5
14
24
29

Hint

For the 11st testcase, one way to achieve minimum is to change the sequence to [1,1,1,0][1,\textbf{1},\textbf{1},\textbf{0}]; the bold numbers are the changed. The final sequence value is 22, and 33 operations are done; the total value ++ cost is 2+3×4=142 + 3 \times 4 = 14.

For the 22nd testcase, one way to achieve minimum is to change the sequence to [6,6,6,6,6,6,6,6][6,6,6,\textbf{6},\textbf{6},6,6,6]; the final value is 12+2×6=2412 + 2 \times 6 = 24.