A4: Generate State 12(∣0⟩−∣2n−1⟩)\frac{1}{\sqrt{2}}\lparen\ket{0}-\ket{2^{n}-1}\rparen II

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 100 points

Problem Statement

You are given an integer nn. Implement the operation of preparing the state ∣ψ⟩\ket{\psi} from the zero state on a quantum circuit qc\mathrm{qc} with nn qubits.

The quantum state ∣ψ⟩\ket{\psi} is defined as

∣ψ⟩=12(∣0...0⟩n−∣1...1⟩n).\begin{equation} \ket{\psi} = \frac{1}{\sqrt{2}} (\ket{0...0}_n - \ket{1...1}_n) \nonumber \end{equation}.

Constraints

  • 2≤n≤152 \leq n \leq 15
  • The circuit depth must not exceed 1010.
  • Global phase is ignored in judge.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit
 
 
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
 
    return qc

Sample Input

  • n=4n = 4: Implemented circuit qc\mathrm{qc} should perform the following transformation.
∣0000⟩→qc12(∣0000⟩−∣1111⟩)\ket{0000} \xrightarrow{\mathrm{qc}} \frac{1}{\sqrt{2}} (\ket{0000} - \ket{1111})

Please sign in to submit your answer.