B2: Convert Bit-Flip into Phase-Flip I

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Problem Statement

You are given an integer nn and an oracle OO. For any pair of integers (x,y)(x,y) satisfying 0x<2n0\leq x\lt 2^n and 0y<20\leq y\lt 2, the oracle OO satisfies

xny1Oxnyf(x)1,\ket{x}_n \ket{y}_1 \xrightarrow{O} \ket{x}_n \ket{y \oplus f(x)}_1,

where \oplus denotes the XOR operator, and f(x)f(x) is a function that returns either 00 or 11 for any integer xx with 0x<2n0\leq x\lt 2^n.

Implement an operation on a quantum circuit qc\mathrm{qc} that satisfies

xn01qc{xn01(f(x)=1)xn01(f(x)=0),\begin{equation} \ket{x}_n\ket{0}_1 \xrightarrow{\mathrm{qc}} \begin{cases} - \ket{x}_n\ket{0}_1 & (f(x) = 1) \\ \ket{x}_n\ket{0}_1 & (f(x) = 0) \end{cases} \nonumber \end{equation},

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

Constraints

  • 1n101\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, 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

Sample Input

  • n=2, (f(00),f(10),f(01),f(11))=(0,1,0,1)n = 2,\ (f(00), f(10), f(01), f(11)) = (0, 1, 0, 1): Implemented circuit qc\mathrm{qc} should perform the following transformation. 14(00+10+01+11)0qc14(0010+0111)0\frac{1}{\sqrt{4}} ( \ket{00}+\ket{10}+\ket{01}+\ket{11} )\ket{0} \xrightarrow{\mathrm{qc}} \frac{1}{\sqrt{4}} (\ket{00} - \ket{10} + \ket{01} - \ket{11})\ket{0}

Please sign in to submit your answer.