Editorial
The expected solution for Problem A3 has a quantum circuit depth of , which exceeds the depth limit of this problem. So, how should we design the quantum circuit?
To reduce the depth of the quantum circuit, it's essential to avoid continuously applying quantum gates to the same qubit. Let’s take a look at the example of a -qubit quantum circuit below:

The difference from the expected solution for Problem A3 is that the control qubit of the rightmost controlled gate has been changed from the st qubit to the nd qubit.
In this case, the rightmost controlled gate acts on the nd and th qubits, while the adjacent gate to the left operates on the st and rd qubits. Since these operations involve different qubit pairs, they can be executed simultaneously, reducing the quantum circuit depth by one.
Let’s examine the transition of the quantum states. Until the application of the second controlled gate, it is the same as the expected solution for Problem A3.
Next, apply a controlled gate with the nd qubit as the control qubit and the th qubit as the target qubit.
Finally, by applying a gate, the phase of is inverted.
When generalizing this idea to a quantum circuit with qubits, first apply a Hadamard gate to the st qubit and a controlled gate with the st qubit as the control qubit and the nd as the target qubit. Then, for , repeat the following operations while the target qubit does not exceed :
- Apply a controlled gate with the st qubit as the control qubit and the -th qubit as the target qubit.
- Apply a controlled gate with the nd qubit as the control qubit and the -th qubit as the target qubit.
For example, when , the following quantum circuit can be constructed.

With the above operations, the depth of the quantum circuit becomes or less, which satisfies the given constraint.
Sample Code
Below is a sample program:
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.h(0)
qc.cx(0, 1)
for i in range(2, n - 1, 2):
qc.cx(0, i)
qc.cx(1, i + 1)
if n % 2 != 0:
qc.cx(0, n - 1)
qc.z(0)
return qc