Problem Statement
Let n be a positive integer. Consider a list [p0,p1,...,p2n−1] of length 2n.
We define Operation 1 and Operation 2 as follows:
- Operation 1: Move the first element to the end
[p0,p1,...,p2n−1]→[p1,...,p2n−1,p0]
- Operation 2: Reverse the entire list
[p0,p1,...,p2n−1]→[p2n−1,...,p1,p0]
Also, for integers m, k with 0≤m<2, 0≤k<2n, let g(m,k) be the concatenation of the following actions:
- First, apply Operation 1 for k times.
- Then, apply Operation 2 for m times.
Given integers n, mbefore, kbefore, mafter and kafter, implement an (n+1)-qubit oracle O on a quantum circuit qc.
The oracle O must satisfy
∣m⟩∣k⟩nO∣m′⟩∣k′⟩n,
where g(m′,k′) must be equivalent to the concatenation of the following actions:
- First, apply g(mbefore,kbefore).
- Then, apply g(m,k).
- Finally, apply g(mafter,kafter).
Constraints
- 2≤n≤10
- 0≤mbefore<2
- 0≤kbefore<2n
- 0≤mafter<2
- 0≤kafter<2n
- The circuit depth must not exceed 300.
- 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
def solve(n: int, m_before: int, k_before: int, m_after: int, k_after: int) -> QuantumCircuit:
qc = QuantumCircuit(n + 1)
# Write your code here:
return qc