B8: Grover's Algorithm II

Time Limit: 5 seconds

Memory Limit: 512 MiB

Score: 300 points

Problem Statement

You are given an integer nn and an oracle OO. There exists an integer LL in the range from 00 (inclusive) to 2n2^n (exclusive), and the oracle OO satisfies

∣x⟩n∣y⟩1→O{∣x⟩n∣y⊕1⟩1(x=L)∣x⟩n∣y⟩1(x≠L)\ket{x}_n \ket{y}_1 \xrightarrow{O} \begin{cases} \ket{x}_n \ket{y\oplus 1}_1 & (x=L) \\ \ket{x}_n\ket{y}_1 & (x\neq L) \end{cases}

for any pair of integers (x,y)(x,y) satisfying 0≤x<2n0\leq x\lt 2^n and 0≤y<20\leq y\lt 2, where ⊕\oplus denotes the XOR operator.

Implement an operation on a quantum circuit qc\mathrm{qc} with n+1n+1 qubits that prepares a quantum state ∣ψ⟩\ket{\psi} from the zero state ∣0⟩\ket{0}, such that ∣L⟩n∣0⟩1\ket{L}_n\ket{0}_1 is observed with a probability of at least 0.90.9 upon measurement.

More Precise Problem Statement

Define the state ∣ψ⟩\ket{\psi} prepared by applying qc\mathrm{qc} to ∣0⟩n+1\ket{0}_{n+1} as

∣ψ⟩=∑i=02n+1−1ai∣i⟩\ket{\psi} = \sum_{i=0}^{2^{n+1}-1} a_i\ket{i}

where aia_i denotes the complex amplitude of the computational basis state ∣i⟩n+1\ket{i}_{n+1}.

Implement qc\mathrm{qc} satisfying following condition:

∣aL∣2≥0.9|a_L|^2 \geq 0.9

Constraints

  • 2≤n≤102 \leq n \leq 10
  • The quantum circuit depth must not exceed 250250.
  • Oracle OO is given as a quantum circuit of depth 11.
  • Integers must be encoded by little-endian.
  • Global phase is ignored in judge.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit, QuantumRegister
 
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
 
 
def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:
 
    return qc

Please sign in to submit your answer.