B6: Grover's Algorithm I

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

Problem Statement

You are given an integer nn and an oracle OO. There exists an integer LL such that 0L<2n0 \leq L \lt 2^n, and the oracle OO satisfies

xnO{xn(x=L)xn(xL)\ket{x}_n \xrightarrow{O} \begin{cases} - \ket{x}_n & (x=L) \\ \ket{x}_n & (x\neq L) \end{cases}

for any integer xx satisfying 0x<2n0 \leq x \lt 2^n.

Implement an operation on a quantum circuit qc\mathrm{qc} with nn qubits that prepares a quantum state ψ\ket{\psi} from the zero state, such that L\ket{L} is observed with a probability of at least 4/2n4/2^n upon measurement.

More Precise Problem Statement

Define the state ψ\ket{\psi} prepared by qc\mathrm{qc} as

ψ=i=02n1aii,\begin{equation} \ket{\psi} = \sum_{i=0}^{2^n-1} a_i\ket{i}, \nonumber \end{equation}

where aia_i denotes the probability amplitude of the computational basis state i\ket{i}.

Implement qc\mathrm{qc} satisfying following condition:

aL242n|a_L|^2 \geq \frac{4}{2^n}

Constraints

  • 3n103 \leq n \leq 10
  • Integers must be encoded by little-endian notation, i.e., 100=1001\ket{100} = 1 \neq \ket{001}.
  • Global phase is ignored in judge.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit
 
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
 
 
def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
 
    return qc

Please sign in to submit your answer.