Editorial
This problem is about amplifying the probability amplitude of a specific computational basis state and assumes the use of Grover's algorithm.
Let us defined the quantum state by
Grover's algorithm consists of the following steps:
- Prepare the quantum state .
- Repeat the next operation called Grover iteration:
- Apply an operation that flips the sign of only the computational basis state to be amplified.
- Apply the operator represented by .
By applying the gates to all qubits, we can prepare the quantum state . In this problem, the operation that flips the sign of only the computational basis state to be amplified is the oracle itself. The operation represented by the operator is the one implemented in B5.
Considering the above, let's calculate the quantum state after performing one Grover iteration.
First, regarding the inner product between the quantum state and :
Noting that the oracle can be expressed as , we see that applying the oracle to gives:
Next, by applying the operator expressed as , we get:
The value of after performing the operation is given by:
Therefore, under the constraint of , it holds that . Thus, by performing Grover's algorithm for one iteration, we can solve this problem.
For the case where , the circuit diagram is shown below.
The Reflect_B4
in the circuit diagram indicates the circuit of problem B4.

Sample Code
Below is a sample program:
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
def reflect(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(range(n))
qc.append(ZGate().control(n - 1), range(n))
qc.x(range(n))
return qc
def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.h(range(n))
qc.compose(o, inplace=True)
qc.h(range(n))
qc.compose(reflect(n), inplace=True)
qc.h(range(n))
return qc