P565 [CF1002D2] Oracle for f(x) = b * x + (1 - b) * (1 - x) mod 2
普及-
题目描述

Implement a quantum oracle on N qubits which implements the following function:

$$f(\vec{x}) = (\vec{b} \cdot \vec{x} + (\vec{1} - \vec{b}) \cdot (\vec{1} - \vec{x})) \mod 2 = \sum_{k=0}^{N-1} (b_k x_k + (1 - b_k) \cdot (1 - x_k)) \mod 2$$

Here $$\vec{b} \in \{0, 1\}^N$$ (a vector of N integers, each of which can be 0 or 1), and $$\overrightarrow{a}$$ is a vector of N 1s.

For an explanation on how this type of quantum oracles works, see Introduction to quantum oracles.

You have to implement an operation which takes the following inputs:

  • an array of N qubits x in arbitrary state (input register), 1 ≤ N ≤ 8,
  • a qubit y in arbitrary state (output qubit),
  • an array of N integers b, representing the vector $$\overrightarrow{b}$$. Each element of b will be 0 or 1.

The operation doesn't have an output; its "output" is the state in which it leaves the qubits.

Your code should have the following signature:

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
123745 0
样例输出
Test passed