problem stringclasses 67
values | user stringlengths 13 13 | submission_order int64 1 57 | result stringclasses 10
values | execution_time stringlengths 0 8 | memory stringclasses 88
values | code stringlengths 47 7.62k |
|---|---|---|---|---|---|---|
QPC003_A5 | AE12D1828E8E7 | 1 | RE | 1921 ms | 156 MiB | '''python
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
for i in range(0, n-1):
theta = math.atan(math.sqrt(n-i-1)) * 2
qc.cry(theta, i, i+1)
qc.cx(i+1, i)
return qc
''' |
QPC003_A5 | AE12D1828E8E7 | 2 | DLE | 2093 ms | 160 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
# theta = []
# for i in range(n-1):
# theta.append(math.atan(math.sqrt(n-i-1))*2)
qc.x(0)
for i in range(0, n-1):
theta = math.atan(math.sqrt(n-i-1)) * 2
qc.cry(theta, i, i+1)
qc.cx(i+1, i)
return qc
''' |
QPC003_A5 | AE12D1828E8E7 | 3 | DLE | 1865 ms | 143 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
for i in range(n-1):
theta = math.atan(math.sqrt(n-1-i)) * 2
qc.cry(theta, i, i+1)
qc.cx(i+1, i)
return qc
''' |
QPC003_A5 | AE12D1828E8E7 | 4 | AC | 1840 ms | 145 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
for i in range(n-1):
theta = math.atan(math.sqrt(n-1-i)) * 2
qc.cry(theta, i, i+1)
for i in range(n-1):
qc.cx(i+1, i)
return qc
''' |
QPC003_A5 | AE46E156EE2BF | 1 | AC | 1934 ms | 158 MiB | '''python
import math
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
theta = [2 * math.atan(math.sqrt(i)) for i in range(n - 1, 0, -1)]
qc.x(0)
for i in range(n-1):
qc.cry(theta[i], i, i + 1)
for i in range(n - 1):
qc.cx(i + 1, i)
return qc
''' |
QPC003_A5 | AE5E2217EF5B3 | 1 | RE | 1476 ms | 153 MiB | '''python
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
theta = [2 * math.atan(math.sqrt(i)) for i in range(n - 1, 0, -1)]
qc.x(0)
for i in range(n - 1):
qc.cry(theta[i], i, i + 1)
for i in range(n - 1):
qc.cx(i + 1,i)
return qc
''' |
QPC003_A5 | AE5E2217EF5B3 | 2 | AC | 2083 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
theta = [2 * math.atan(math.sqrt(i)) for i in range(n - 1, 0, -1)]
qc.x(0)
for i in range(n - 1):
qc.cry(theta[i], i, i + 1)
for i in range(n - 1):
qc.cx(i + 1,i)
return qc
''' |
QPC003_A5 | AED641CB08B79 | 1 | AC | 1961 ms | 157 MiB | '''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import CXGate, ZGate
from math import sqrt, acos, pi
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
def solve_for(l, r):
if r - l == 1:
return
m = l + r >> 1
theta = 2 * acos(sqrt(m - l) / sqrt(r - l))
qc.cry(theta, l, m)
qc.cx(m, l)
solve_for(l, m)
solve_for(m, r)
solve_for(0, n)
return qc
''' |
QPC003_A5 | AF2DC2FEC97D3 | 1 | RE | 1227 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
theta=[2*math.atan(math.sqrt(i)) for i in range(n-1,0,-1)]
qc.x(0)
for i in range(n-1):
qc.cry(theta[i],i,i+1)
qc.cx(i+1,i)
return qc
''' |
QPC003_A5 | AF2DC2FEC97D3 | 2 | DLE | 1611 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
theta=[2*math.atan(math.sqrt(i)) for i in range(n-1,0,-1)]
qc.x(0)
for i in range(n-1):
qc.cry(theta[i],i,i+1)
qc.cx(i+1,i)
return qc
''' |
QPC003_A5 | AF2DC2FEC97D3 | 3 | AC | 1615 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
theta=[2*math.atan(math.sqrt(i)) for i in range(n-1,0,-1)]
qc.x(0)
for i in range(n-1):
qc.cry(theta[i],i,i+1)
for i in range(n-1):
qc.cx(i+1,i)
return qc
''' |
QPC003_A5 | AF468BBCA492E | 1 | AC | 1763 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
for i in range( n - 1 ):
x = math.sqrt(1/ (n-i))
y = math.sqrt((n-i-1)/(n-i))
theta = 2 * math.atan(y/x)
if i == 0:
qc.ry(theta, i)
else:
qc.cry(theta, i-1, i)
qc.x(n-1)
qc.cx(0,n-1)
for i in range(n-2):
qc.cx(i+1,i)
return qc
''' |
QPC003_A5 | AF7A7E7011860 | 1 | RE | 1217 ms | 153 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.ry(2*math.arccos(1/math.sqrt(n)))
for target in range(1, n-1):
qc.ch(target-1, target)
for target in range(n-1, 0, -1):
qc.cx(target-1, target)
qc.x(0)
return qc
''' |
QPC003_A5 | AF7A7E7011860 | 2 | RE | 1395 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.ry(2*math.acos(1/math.sqrt(n)), 0)
for target in range(1, n-1):
qc.ch(target-1, target)
for target in range(n-1, 0, -1):
qc.cx(target-1, target)
qc.x(0)
''' |
QPC003_A5 | AF7A7E7011860 | 3 | WA | 1655 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.ry(2*math.acos(1/math.sqrt(n)), 0)
for target in range(1, n-1):
qc.ch(target-1, target)
for target in range(n-1, 0, -1):
qc.cx(target-1, target)
qc.x(0)
return qc
''' |
QPC003_A6 | A06D65F8EEDB4 | 1 | WA | 1291 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
# Hゲートを各量子ビットに適用して、均等な重ね合わせを作成
for i in range(n):
qc.h(i)
# 各量子ビットが1つだけ1となる状態の測定を行う
return qc
# n の値を指定
n = 4 # 例として n = 4 の場合
qc = solve(n)
''' |
QPC003_A6 | A1083088BF7F0 | 1 | AC | 1647 ms | 158 MiB | '''python
from qiskit import QuantumCircuit
import math
# from qiskit.quantum_info import Statevector
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
a = [[0]*n for _ in range(5)]
for i in range(n):
a[4][i] = 1
for i in range(3, -1, -1):
for j in range(n):
a[i][j] = a[i+1][j]
if j+2**i<n:
a[i][j] += a[i+1][j+2**i]
for i in range(4):
if 2**i>=n:
break
for j in range(0, 2**i):
if j+2**i<n:
qc.cry(math.acos(math.sqrt(a[i+1][j]/a[i][j]))*2, j, j+2**i)
qc.cx(j+2**i, j)
# print(qc.depth())
return qc
# if __name__ == "__main__":
# qc = solve(15)
#print(Statevector(qc))
''' |
QPC003_A6 | A2023E79DE587 | 1 | AC | 1898 ms | 157 MiB | '''python
from math import (
pi,
# degrees,
# radians,
asin,
acos,
# atan2,
sqrt,
# sin,
# cos,
# tan
)
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister
# from qiskit.circuit.library.standard_gates import (
# C3XGate,
# C3SXGate,
# C4XGate,
# CCXGate,
# DCXGate,
# CHGate,
# CPhaseGate,
# CRXGate,
# CRYGate,
# CRZGate,
# CSwapGate,
# CSXGate,
# CUGate,
# CU1Gate,
# CU3Gate,
# CXGate,
# CYGate,
# CZGate,
# CCZGate,
# HGate,
# IGate,
# MCPhaseGate,
# PhaseGate,
# RCCXGate,
# RC3XGate,
# RXGate,
# RXXGate,
# RYGate,
# RYYGate,
# RZGate,
# RZZGate,
# RZXGate,
# XXMinusYYGate,
# XXPlusYYGate,
# ECRGate,
# SGate,
# SdgGate,
# CSGate,
# CSdgGate,
# SwapGate,
# iSwapGate,
# SXGate,
# SXdgGate,
# TGate,
# TdgGate,
# UGate,
# U1Gate,
# U2Gate,
# U3Gate,
# XGate,
# YGate,
# ZGate,
# )
def split_state(qc: QuantumCircuit, targets: list[int], proportions: list[float]):
sum_p = sum(proportions)
proportions = [p / sum_p for p in proportions]
for i in range(1, len(targets)):
qc.cry(
asin(sqrt((1 - sum(proportions[:i])) / (1 - sum(proportions[: i - 1]))))
* 2,
targets[i - 1],
targets[i],
)
for i in range(1, len(targets)):
qc.cx(targets[i], targets[i - 1])
def solve_main(qc: QuantumCircuit, i0: int, i1: int):
if i1 - i0 <= 1:
return
i = (i0 + i1) // 2
split_state(qc, [i0, i], [len(range(i0, i)), len(range(i, i1))])
solve_main(qc, i0, i)
solve_main(qc, i, i1)
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
solve_main(qc, 0, n)
return qc
''' |
QPC003_A6 | A360D33416DD5 | 1 | AC | 3000 ms | 162 MiB | '''python
from qiskit import QuantumCircuit
import numpy as np
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
levels = int(np.ceil(np.log2(n)))
qc.x(0)
box = [0 for _ in range(n)]
box[0] = n
for level in range(levels):
tmp = 2**level
for i in range(tmp):
parent = box[i]
if parent == 1:
continue
left = parent//2
right = parent - left
prob_amp = np.sqrt(left / parent)
rot_ang = 2 * np.arccos(prob_amp)
for j in range(tmp, n):
if box[j] == 0:
bridge = j
break
qc.cry(rot_ang, i, bridge)
qc.cx(bridge, i)
box[i] = left
box[bridge] = right
return qc
''' |
QPC003_A6 | A401D7AC122B3 | 1 | AC | 2996 ms | 161 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
n_code = bin(n)[2:]
m = [0]
for i in range(len(n_code)):
if n_code[i] == "1":
m.append(m[-1]+2**(len(n_code)-i-1))
qc.x(0)
for i in range(1,len(m)-1):
print(i,m[i-1],m[i],(m[i]-m[i-1])/(n-m[i-1]))
split_one_hot(qc,m[i-1],m[i],(m[i]-m[i-1])/(n-m[i-1]))
for j in range(1,len(m)):
for k in range(1,m[j]-m[j-1]):
split_one_hot(qc,m[j-1]+k-2**int(math.log2(k)),m[j-1]+k,1/2)
return qc
def split_one_hot(qc,m1,m2,l):
print(m1,m2,l)
qc.cry(2*math.acos(math.sqrt(l)),m1,m2)
qc.cx(m2,m1)
''' |
QPC003_A6 | A43AB9FAB5173 | 1 | AC | 1832 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
from math import acos, pi, sqrt
def func(qc, l:int, r:int) -> QuantumCircuit:
m = (l + r) // 2
theta = 2 * acos(sqrt((m - l)/(r - l)))
qc.cry(theta, l, m)
qc.cx(m, l)
if m - l > 1:
func(qc, l, m)
if r - m > 1:
func(qc, m, r)
return qc
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
func(qc, 0, n)
return qc
''' |
QPC003_A6 | A447E8F89BAA6 | 1 | AC | 2516 ms | 161 MiB | '''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, XGate, HGate, SwapGate
import math
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def diffusion_oracle(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
for i in range(n):
qc.h(i)
qc.x(i)
qc.append(ZGate().control(n - 1), range(n))
for i in range(n):
qc.x(i)
qc.h(i)
return qc
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
count = 1
# queue = [(a, b, control bit of CRy), ...]
queue = [(n // 2, n, 0)]
# breadth first search
while len(queue):
a, b, control = queue.pop(0)
if a == 0:
continue
theta = 2 * math.atan(math.sqrt((b - a) / a))
qc.cry(theta, control, count)
qc.cx(count, control)
queue.append(((b // 2) // 2, b // 2, control))
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
# if __name__ == "__main__":
# from qiskit.quantum_info import Statevector
# import numpy as np
# n = 3
# qc = solve(n)
# sv = Statevector(qc)
# print(sv)
# print(qc)
# print(f"{qc.depth() = }")
# # sv = Statevector.from_label('01000')
# # print(sv.evolve(qc))
''' |
QPC003_A6 | A4CE75FBB8F18 | 1 | AC | 1841 ms | 158 MiB | '''python
from qiskit import QuantumCircuit
import numpy as np
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
levels = int(np.ceil(np.log2(n)))
qc.x(0)
box = [0 for _ in range(n)]
box[0] = n
for level in range(levels):
tmp = 2**level
for i in range(tmp):
parent = box[i]
if parent == 1:
continue
left = parent//2
right = parent - left
prob_amp = np.sqrt(left / parent)
rot_ang = 2 * np.arccos(prob_amp)
for j in range(tmp, n):
if box[j] == 0:
bridge = j
break
qc.cry(rot_ang, i, bridge)
qc.cx(bridge, i)
box[i] = left
box[bridge] = right
return qc
''' |
QPC003_A6 | A577FE2EE85AA | 1 | AC | 2164 ms | 157 MiB | '''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import CXGate, ZGate
from math import sqrt, acos, pi
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
def solve_for(l, r):
if r - l == 1:
return
m = l + r >> 1
theta = 2 * acos(sqrt(m - l) / sqrt(r - l))
qc.cry(theta, l, m)
qc.cx(m, l)
solve_for(l, m)
solve_for(m, r)
solve_for(0, n)
return qc
''' |
QPC003_A6 | A5A26A2557EEF | 1 | WA | 1935 ms | 159 MiB | '''python
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Apply Hadamard to the first qubit to create superposition
qc.h(0)
# Apply controlled NOT gates to create the desired states
for i in range(1, n):
qc.cx(0, i) # Control on qubit 0, target on qubit i
# Apply a normalization factor (not explicitly in the circuit, but conceptually)
# The state is already normalized due to the structure of the circuit.
return qc
''' |
QPC003_A6 | A5BB29562F6C5 | 1 | AC | 1662 ms | 157 MiB | '''python
import math
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
count = 1
# queue = [(a, b, control bit of CRy), ...]
queue = [(n // 2, n, 0)]
# breadth first search
while len(queue):
a, b, control = queue.pop(0)
if a == 0:
continue
theta = 2 * math.atan(math.sqrt((b - a) / a))
qc.cry(theta, control, count)
qc.cx(count, control)
queue.append(((b // 2) // 2, b // 2, control))
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | A87B626930645 | 1 | UME | '''python
from math import *
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
cnt=1
que=[(n,0)]
while len(que):
a,ctrl=que.pop(0)
if a == 0 or a==1:
continue
b=ceil(a/2)
c=floor(a/2)
t=2*acos(sqrt(b/a))
qc.cry(t,ctrl,cnt)
qc.cx(cnt,ctrl)
que.append((b,ctrl))
que.append((c,cnt))
cnt+=1
return qc
''' | ||
QPC003_A6 | A87B626930645 | 2 | AC | 3000 ms | 162 MiB | '''python
from math import ceil,floor,acos,sqrt
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
cnt=1
que=[(n,0)]
while len(que):
a,ctrl=que.pop(0)
if a == 0 or a==1:
continue
b=ceil(a/2)
c=floor(a/2)
t=2*acos(sqrt(b/a))
qc.cry(t,ctrl,cnt)
qc.cx(cnt,ctrl)
que.append((b,ctrl))
que.append((c,cnt))
cnt+=1
return qc
''' |
QPC003_A6 | A8FBCAE11B4D6 | 1 | RE | 1836 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
count = 1
queue = [(n//2, n, 0)]
while len(queue):
a,b,control = queue.pop()
if a == 0:
continue;
qc.cry(2 * math.atan(math.sqrt((b - a) / a)),control,count)
qc.cx(count,control)
qc.append(((b // 2) // 2,b // 2, control))
qc.append((math.ceil(b / 2) // 2,math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | A8FBCAE11B4D6 | 2 | RE | 1443 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
count = 1
queue = [(n//2, n, 0)]
while len(queue):
a,b,control = queue.pop(0)
if a == 0:
continue;
qc.cry(2 * math.atan(math.sqrt((b - a) / a)),control,count)
qc.cx(count,control)
qc.append(((b // 2) // 2,b // 2, control))
qc.append((math.ceil(b / 2) // 2,math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | A8FBCAE11B4D6 | 3 | RE | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc = QuantumCircuit(n)
qc.x(0)
count = 1
queue = [(n//2, n, 0)]
while len(queue):
a,b,control = queue.pop(0)
continue;
if a > 0 and b > a:
qc.cry(2 * math.atan(math.sqrt((b - a) / a)),control,count)
qc.cx(count,control)
if b // 2 > 0:
qc.cx(control, count)
queue.append(((b // 2) // 2, b // 2, control))
if math.ceil(b / 2) // 2 > 0:
qc.cx(count, control)
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' | ||
QPC003_A6 | A8FBCAE11B4D6 | 4 | WA | 1652 ms | 160 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc = QuantumCircuit(n)
qc.x(0)
count = 1
queue = [(n//2, n, 0)]
while len(queue):
a,b,control = queue.pop(0)
if a == 0:
continue;
if a > 0 and b > a:
qc.cry(2 * math.atan(math.sqrt((b - a) / a)),control,count)
qc.cx(count,control)
if b // 2 > 0:
qc.cx(control, count)
queue.append(((b // 2) // 2, b // 2, control))
if math.ceil(b / 2) // 2 > 0:
qc.cx(count, control)
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | A8FBCAE11B4D6 | 5 | AC | 2919 ms | 161 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
count = 1
queue = [(n//2, n, 0)]
while len(queue):
a,b,control = queue.pop(0)
if a == 0:
continue;
qc.cry(2 * math.atan(math.sqrt((b - a) / a)),control,count)
qc.cx(count,control)
queue.append(((b // 2) // 2, b // 2, control))
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | A98FFACF6AFED | 1 | WA | 2156 ms | 160 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
keep = [n]
qc.x(0)
for i in range(int(math.log2(n)) + 1):
for j in range(2**i):
if 2**i + j < n:
x = keep.pop(0)
a = (x + 1) // 2
b = x // 2
keep.append(a)
keep.append(b)
theta = 2 * math.atan(math.sqrt(b / a))
qc.cry(theta, j, j + 2**i)
print(keep)
for k in range(2**i):
if 2 ** i + k < n:
qc.cx(k + 2**i, k)
return qc
''' |
QPC003_A6 | A98FFACF6AFED | 2 | WA | 2525 ms | 161 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
keep = [n]
qc.x(0)
for i in range(int(math.log2(n)) + 1):
for j in range(2**i):
if 2**i + j < n:
x = keep.pop(0)
a = (x + 1) // 2
b = x // 2
keep.append(a)
keep.append(b)
theta = 2 * math.atan(math.sqrt(b / a))
qc.cry(theta, j, j + 2**i)
for k in range(2**i):
if 2 ** i + k < n:
qc.cx(k + 2**i, k)
return qc
''' |
QPC003_A6 | A98FFACF6AFED | 3 | WA | 1974 ms | 160 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
keep = [n]
qc.x(0)
for i in range(int(math.log2(n)) + 1):
for j in range(2**i):
# print(2**i + j)
if 2**i + j < n:
x = keep.pop(0)
a = (x + 1) // 2
b = x // 2
if a > 1:
keep.append(a)
if b > 1:
keep.append(b)
theta = 2 * math.atan(math.sqrt(b / a))
qc.cry(theta, j, j + 2**i)
# print(keep)
for k in range(2**i):
if 2 ** i + k < n:
qc.cx(k + 2**i, k)
return qc
''' |
QPC003_A6 | A98FFACF6AFED | 4 | AC | 2273 ms | 161 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
keep = {0:n}
qc.x(0)
for i in range(int(math.log2(n)) + 1):
for j in range(2**i):
# print(2**i + j)
if 2**i + j < n:
x = keep.pop(j)
a = (x + 1) // 2
b = x // 2
# print(a, b)
if a > 1:
keep[j] = a
if b > 1:
keep[j + 2**i] = b
theta = 2 * math.atan(math.sqrt(b / a))
qc.cry(theta, j, j + 2**i)
# print(keep)
for k in range(2**i):
if 2 ** i + k < n:
qc.cx(k + 2**i, k)
return qc
''' |
QPC003_A6 | AA0448EDA2336 | 1 | DLE | 1701 ms | 156 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
for i in range( n - 1 ):
x = math.sqrt(1/ (n-i))
y = math.sqrt((n-i-1)/(n-i))
theta = 2 * math.atan(y/x)
if i == 0:
qc.ry(theta, i)
else:
qc.cry(theta, i-1, i)
qc.x(n-1)
qc.cx(0,n-1)
for i in range(n-2):
qc.cx(i+1,i)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 1 | WA | 1590 ms | 156 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 13:
qc.x(0)
qc.cry(2*math.acos(math.sqrt(5.0/n)), 0, 5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
for i in range(n-10):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(n-10):
qc.cry(-math.pi, i+10, i+9)
elif n < 15:
qc.x(0)
qc.cry(2*math.acos(math.sqrt(5.0/n)), 0, 5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
qc.cry(2*math.acos(math.sqrt(3.0/(n-9))), 9, 12)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(2):
qc.cry(-math.pi, i+10, i+9)
for i in range(n-13):
qc.cry(2*math.acos(1.0/math.sqrt(n-13-i)), i+12, i+13)
for i in range(n-13):
qc.cry(-math.pi, i+13, i+12)
else:
qc.x(0)
qc.cry(2*math.acos(math.sqrt(5.0/n)), 0, 5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
qc.cry(2*math.acos(math.sqrt(3.0/(n-9))), 9, 12)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(2):
qc.cry(-math.pi, i+10, i+9)
qc.cry(2*math.acos(math.sqrt(2.0/(n-12))), 12, 14)
for i in range(1):
qc.cry(2*math.acos(1.0/math.sqrt(n-13-i)), i+12, i+13)
for i in range(1):
qc.cry(-math.pi, i+13, i+12)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 2 | WA | 1709 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 13:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
for i in range(n-10):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(n-10):
qc.cry(-math.pi, i+10, i+9)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
qc.cry(2*math.acos(math.sqrt(3.0/(n-9))), 9, 12)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(2):
qc.cry(-math.pi, i+10, i+9)
for i in range(n-13):
qc.cry(2*math.acos(1.0/math.sqrt(n-13-i)), i+12, i+13)
for i in range(n-13):
qc.cry(-math.pi, i+13, i+12)
else:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
qc.cry(2*math.acos(math.sqrt(3.0/(n-9))), 9, 12)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(2):
qc.cry(-math.pi, i+10, i+9)
qc.cry(2*math.acos(math.sqrt(2.0/(n-12))), 12, 14)
for i in range(1):
qc.cry(2*math.acos(1.0/math.sqrt(n-13-i)), i+12, i+13)
for i in range(1):
qc.cry(-math.pi, i+13, i+12)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 3 | WA | 1590 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 13:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
qc.cx(9, 5)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
for i in range(n-10):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(n-10):
qc.cry(-math.pi, i+10, i+9)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
qc.cx(9, 5)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
qc.cry(2*math.acos(math.sqrt(3.0/(n-9))), 9, 12)
qc.cx(12, 9)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(2):
qc.cry(-math.pi, i+10, i+9)
for i in range(n-13):
qc.cry(2*math.acos(1.0/math.sqrt(n-13-i)), i+12, i+13)
for i in range(n-13):
qc.cry(-math.pi, i+13, i+12)
else:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
qc.cry(2*math.acos(math.sqrt(4.0/(n-5))), 5, 9)
qc.cx(9, 5)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(3):
qc.cry(-math.pi, i+6, i+5)
qc.cry(2*math.acos(math.sqrt(3.0/(n-9))), 9, 12)
qc.cx(12, 9)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(n-9-i)), i+9, i+10)
for i in range(2):
qc.cry(-math.pi, i+10, i+9)
qc.cry(2*math.acos(math.sqrt(2.0/(n-12))), 12, 14)
qc.cx(14, 12)
for i in range(1):
qc.cry(2*math.acos(1.0/math.sqrt(n-13-i)), i+12, i+13)
for i in range(1):
qc.cry(-math.pi, i+13, i+12)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 4 | RE | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8)), 8, 11)
qc.cx(11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8)), 8, 11)
qc.cx(11, 8)
qc.cry(2*math.acos(math.sqrt(0.5), 11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.ch(13, 14)
return qc
''' | ||
QPC003_A6 | AA7955557FD95 | 5 | RE | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8)), 8, 11)
qc.cx(11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8)), 8, 11)
qc.cx(11, 8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.ch(13, 14)
return qc
''' | ||
QPC003_A6 | AA7955557FD95 | 6 | RE | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8)), 8, 11)
qc.cx(11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8)), 8, 11)
qc.cx(11, 8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.ch(13, 14)
return qc
''' | ||
QPC003_A6 | AA7955557FD95 | 7 | RE | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8)), 8, 11)
qc.cx(11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cx(11, 8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.ch(13, 14)
return qc
''' | ||
QPC003_A6 | AA7955557FD95 | 8 | WA | 1300 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cx(11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cx(11, 8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.ch(13, 14)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 9 | WA | 1597 ms | 158 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5)), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5)), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cx(11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5)), 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cx(11, 8)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 13)
qc.cx(13, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 12)
qc.cry(-math.pi, 12, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 13, 14)
qc.cry(-math.pi, 14, 13)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 10 | WA | 1605 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5)), 0, 4)
qc.cry(-math.pi, 4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5)), 0, 4)
qc.cry(-math.pi, 4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.cry(2*math.acos(math.sqrt(0.5)), 0, 4)
qc.cry(-math.pi, 4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 13)
qc.cry(-math.pi, 13, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 12)
qc.cry(-math.pi, 12, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 13, 14)
qc.cry(-math.pi, 14, 13)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 11 | RE | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(, 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(, 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(, 0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 13)
qc.cry(-math.pi, 13, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 12)
qc.cry(-math.pi, 12, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 13, 14)
qc.cry(-math.pi, 14, 13)
return qc
''' | ||
QPC003_A6 | AA7955557FD95 | 12 | WA | 1545 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 13)
qc.cry(-math.pi, 13, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 12)
qc.cry(-math.pi, 12, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 13, 14)
qc.cry(-math.pi, 14, 13)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 13 | WA | 1864 ms | 158 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 13)
qc.cry(-math.pi, 13, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 11, 12)
qc.cry(-math.pi, 12, 11)
qc.cry(2*math.acos(math.sqrt(0.5)), 13, 14)
qc.cry(-math.pi, 14, 13)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 14 | WA | 1838 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cx(11, 8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.cx(12, 11)
qc.ch(13, 14)
qc.cx(14, 13)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 15 | WA | 1671 ms | 158 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.cx(12, 11)
qc.ch(13, 14)
qc.cx(14, 13)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 16 | WA | 2128 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.cx(12, 11)
qc.ch(13, 14)
qc.cx(14, 13)
return qc
''' |
QPC003_A6 | AA7955557FD95 | 17 | AC | 1734 ms | 158 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n < 6:
qc.ry(2*math.acos(1.0/math.sqrt(n)), 0)
for i in range(n-2):
qc.cry(2*math.acos(1.0/math.sqrt(n-i-1)), i, i+1)
for i in range(n-1):
qc.cry(-math.pi, n-2-i, n-1-i)
qc.ry(-math.pi, 0)
elif n < 10:
qc.ry(2*math.acos(math.sqrt((n-5.0)/n)), 5)
qc.cx(5, 0)
qc.x(5)
for i in range(4):
qc.cry(2*math.acos(1.0/math.sqrt(5-i)), i, i+1)
for i in range(4):
qc.cry(-math.pi, i+1, i)
for i in range(n-6):
qc.cry(2*math.acos(1.0/math.sqrt(n-5-i)), i+5, i+6)
for i in range(n-6):
qc.cry(-math.pi, i+6, i+5)
elif n < 12:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
for i in range(n-9):
qc.cry(2*math.acos(1.0/math.sqrt(n-8-i)), i+8, i+9)
for i in range(n-9):
qc.cry(-math.pi, i+9, i+8)
elif n < 15:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
for i in range(n-12):
qc.cry(2*math.acos(1.0/math.sqrt(n-11-i)), i+11, i+12)
for i in range(n-12):
qc.cry(-math.pi, i+12, i+11)
else:
qc.ry(2*math.acos(math.sqrt((n-8.0)/n)), 8)
qc.cx(8, 0)
qc.x(8)
qc.ch(0, 4)
qc.cx(4, 0)
for i in range(3):
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i, i+1)
qc.cry(2*math.acos(1.0/math.sqrt(4-i)), i+4, i+5)
for i in range(3):
qc.cry(-math.pi, i+1, i)
qc.cry(-math.pi, i+5, i+4)
qc.cry(2*math.acos(math.sqrt(3.0/(n-8))), 8, 11)
qc.cry(-math.pi, 11, 8)
for i in range(2):
qc.cry(2*math.acos(1.0/math.sqrt(3-i)), i+8, i+9)
for i in range(2):
qc.cry(-math.pi, i+9, i+8)
qc.ch(11, 13)
qc.cx(13, 11)
qc.ch(11, 12)
qc.cx(12, 11)
qc.ch(13, 14)
qc.cx(14, 13)
return qc
''' |
QPC003_A6 | AC3CF6A8D1CBB | 1 | RE | 1381 ms | 153 MiB | '''python
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
count = 1
queue = [(n // 2, n, 0)]
while len(quque):
a, b, control = queue.pop(0)
if a == 0:
continue
theta = 2 * math.atan(math.sqrt((b - a) / a))
qc.cry(theta, control, count)
qc.cx(count, control)
queue.append(((b // 2) // 2, b // 2, control))
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | AC3CF6A8D1CBB | 2 | RE | 1609 ms | 153 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
count = 1
queue = [(n // 2, n, 0)]
while len(quque):
a, b, control = queue.pop(0)
if a == 0:
continue
theta = 2 * math.atan(math.sqrt((b - a) / a))
qc.cry(theta, control, count)
qc.cx(count, control)
queue.append(((b // 2) // 2, b // 2, control))
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | AC3CF6A8D1CBB | 3 | AC | 1831 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
count = 1
queue = [(n // 2, n, 0)]
while len(queue):
a, b, control = queue.pop(0)
if a == 0:
continue
theta = 2 * math.atan(math.sqrt((b - a) / a))
qc.cry(theta, control, count)
qc.cx(count, control)
queue.append(((b // 2) // 2, b // 2, control))
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | ACB622EC8767A | 1 | AC | 2138 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
count = 1
# queue = [(a, b, control bit of CRy), ...]
queue = [(n // 2, n, 0)]
# breadth first search
while len(queue):
a, b, control = queue.pop(0)
if a == 0:
continue
theta = 2 * math.atan(math.sqrt((b - a) / a))
qc.cry(theta, control, count)
qc.cx(count, control)
queue.append(((b // 2) // 2, b // 2, control))
queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
count += 1
return qc
''' |
QPC003_A6 | AD52F4C325A5A | 1 | AC | 1738 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
from math import pi, acos, sqrt
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
def f(l: int, r: int) -> None:
if r - l == 1:
return
mid = (l + r) // 2
qc.cry(2 * acos(sqrt((mid-l)/(r-l))), l, mid)
qc.cx(mid, l)
f(l, mid)
f(mid, r)
f(0, n)
return qc
''' |
QPC003_A6 | AE201A7C55123 | 1 | AC | 1777 ms | 157 MiB | '''python
from qiskit import QuantumCircuit
from math import asin
def move(qc, f, t, ratio):
theta = 2 * asin(ratio**0.5)
qc.cry(theta, f, t)
qc.cx(t, f)
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
parent = [None]
for i in range(1, n):
for r in (8, 4, 2, 1):
if i & r:
parent.append(i - r)
break
# print(parent)
ww = [0] * n
for i in range(n - 1, -1, -1):
ww[i] += 1 / n
if parent[i] is not None:
ww[parent[i]] += ww[i]
# print(ww)
xx = [0] * n
xx[0] = 1
for i in range(1, n):
p = parent[i]
move(qc, p, i, ww[i] / xx[p])
xx[p] -= ww[i]
xx[i] = ww[i]
return qc
''' |
QPC003_A6 | AE28B0E89E1E1 | 1 | RE | 1307 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
import math
def theta(n: int, m: int) -> float:
return 2 * math.acos(math.sqrt(m/n))
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
a = 1
while a*2 < n:
a *= 2
qc.x(0)
while a > 0:
j = 0
while j + a <= n:
print(j, j+a)
qc.cry(theta(min(2*a,n), a), j, j+a)
qc.cx(j+a,j)
j += a+1
a //= 2
return qc
''' |
QPC003_A6 | AE28B0E89E1E1 | 2 | RE | 1599 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
def theta(n: int, m: int) -> float:
return 2 * math.acos(math.sqrt(m/n))
a = 1
while a*2 < n:
a *= 2
qc.x(0)
while a > 0:
j = 0
while j + a <= n:
print(j, j+a)
qc.cry(theta(min(2*a,n), a), j, j+a)
qc.cx(j+a,j)
j += a+1
a //= 2
return qc
''' |
QPC003_A6 | AE28B0E89E1E1 | 3 | WA | 1286 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
def theta(n: int, m: int) -> float:
return 2 * math.acos(math.sqrt(m/n))
a = 1
while a*2 < n:
a *= 2
qc.x(0)
while a > 0:
j = 0
while j + a < n:
# print(j, j+a)
qc.cry(theta(min(2*a, n), a), j, j+a)
qc.cx(j+a,j)
j += a+1
a //= 2
return qc
''' |
QPC003_A6 | AE28B0E89E1E1 | 4 | AC | 1705 ms | 156 MiB | '''python
from qiskit import QuantumCircuit
import math
def theta(n: int, m: int) -> float:
return 2 * math.acos(math.sqrt(m/n))
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
a = 1
while a*2 < n:
a *= 2
qc.x(0)
while a > 0:
j = 0
while j + a < n:
qc.cry(theta(min(2*a, n-j), a), j, j+a)
qc.cx(j+a, j)
j += 2*a
a //= 2
return qc
''' |
QPC003_A6 | AE345EC443A0F | 1 | AC | 1895 ms | 157 MiB | '''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import GlobalPhaseGate
import numpy as np
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
split(qc, 0, n)
return qc
def split(qc, stIncl, edExcl):
if stIncl + 1 == edExcl:
return
mid = (stIncl + edExcl) // 2
left = mid - stIncl
right = edExcl - mid
print(f'{left=} {right=}')
angle = 2*math.atan(math.sqrt(right/left))
qc.cry(angle, stIncl, mid)
qc.cx(mid, stIncl)
split(qc, stIncl, mid)
split(qc, mid, edExcl)
return qc
''' |
QPC003_A6 | AF500A187CD5A | 1 | AC | 1870 ms | 156 MiB | '''python
from qiskit import QuantumCircuit
import math
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
# Write your code here:
qc.x(0)
for i,j in [(0,8),(0,4),(8,12),(0,2),(4,6),(8,10),(12,14),(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13)]:
if j >= n:
continue
theta = math.atan(math.sqrt(min(j-i,n-j)/(j-i)))*2
qc.cry(theta, i, j)
qc.cx(j,i)
return qc
''' |
QPC003_A6 | AFAEA9300DEC6 | 1 | UGE | 1379 ms | 154 MiB | '''python
import math
from qiskit import QuantumCircuit
def theta(l: int, k: int) -> float:
return math.asin(math.sqrt(l/k)) * 2
def solve_inner(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
if n == 1:
return qc
else:
half = n // 2
qc_l = solve_inner(half)
qc_r = solve_inner(n - half)
qc.cry(theta(n-half, n), 0, half)
qc.cx(half, 0)
qc.append(qc_l, range(half))
qc.append(qc_r, range(half, n))
return qc
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
qc.append(solve_inner(n), range(n))
return qc
if __name__ == "__main__":
qc = solve_inner(3)
print(qc)
''' |
QPC003_A6 | AFAEA9300DEC6 | 2 | AC | 1931 ms | 158 MiB | '''python
import math
from qiskit import QuantumCircuit
def theta(l: int, k: int) -> float:
return math.asin(math.sqrt(l/k)) * 2
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x(0)
def solve_inner(k: int, l: int, qc_l: QuantumCircuit) -> QuantumCircuit:
if k == 1:
return qc_l
else:
half = k // 2
qc_l.cry(theta(k-half, k), l, l + half)
qc_l.cx(l + half, l)
qc_l = solve_inner(half, l, qc_l)
qc_l = solve_inner(k - half, l + half, qc_l)
return qc_l
qc = solve_inner(n, 0, qc)
return qc
if __name__ == "__main__":
qc = solve(3)
print(qc)
''' |
QPC003_B1 | A07BB9D724C52 | 1 | AC | 1409 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
qc.x(0)
return qc
''' |
QPC003_B1 | A085687CE583B | 1 | RE | 1559 ms | 153 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.cx(0,1)
return qc
''' |
QPC003_B1 | A085687CE583B | 2 | AC | 1588 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A09DA4793FCDE | 1 | AC | 1412 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A0CA361036427 | 1 | AC | 1236 ms | 155 MiB | '''python
import numpy as np
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
qc.x(0)
return qc
''' |
QPC003_B1 | A0CCD63326EF3 | 1 | WA | 1569 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
qc.y(0)
return qc
''' |
QPC003_B1 | A0CCD63326EF3 | 2 | AC | 1498 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
qc.x(0)
return qc
''' |
QPC003_B1 | A0CFA971975DF | 1 | AC | 1683 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A1017BC0CD196 | 1 | AC | 1576 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
qc.x(0)
return qc
''' |
QPC003_B1 | A10F87143A09A | 1 | AC | 1376 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A153051CCFE83 | 1 | AC | 1639 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A171D50FBA79E | 1 | AC | 1653 ms | 142 MiB | '''python
from qiskit import QuantumCircuit
import numpy as np
# from qiskit.quantum_info import Statevector
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
# if __name__ == "__main__":
# qc = solve()
# print(Statevector(qc))
''' |
QPC003_B1 | A1BF89254EDA9 | 1 | AC | 1642 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A1CDA20FCAD97 | 1 | RE | 1215 ms | 153 MiB | '''python
from qiskit import QuantumCircuit
from math import pi, acos, sqrt
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(1)
qc.x(0)
return qc
''' |
QPC003_B1 | A1CDA20FCAD97 | 2 | RE | 1599 ms | 153 MiB | '''python
from qiskit import QuantumCircuit
from math import pi, acos, sqrt
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(1)
qc.x(0)
return qc
''' |
QPC003_B1 | A1CDA20FCAD97 | 3 | AC | 1370 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A1DB4E247AE36 | 1 | AC | 1493 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A1EE323474711 | 1 | AC | 1573 ms | 142 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A1F138E2EC9E9 | 1 | AC | 1552 ms | 156 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A292DFFE7CED7 | 1 | AC | 1527 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A2B0590076D37 | 1 | AC | 1897 ms | 154 MiB | '''python
import math
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
if __name__ == "__main__":
qc = solve()
print(qc)
''' |
QPC003_B1 | A2DDDE40001D0 | 1 | AC | 1771 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import GlobalPhaseGate
import math
# from qiskit.quantum_info import Statevector
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
# if __name__ == "__main__":
# qc = solve()
# print(Statevector(qc))
''' |
QPC003_B1 | A2EBF549C10C6 | 1 | AC | 1836 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A2F0D226654F8 | 1 | AC | 1435 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A2FD3A68777D1 | 1 | AC | 1528 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A2FF997417378 | 1 | AC | 1521 ms | 160 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A33BB6BB2D303 | 1 | AC | 1560 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A33F09B066F34 | 1 | WA | 1625 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.h(0)
return qc
''' |
QPC003_B1 | A33F09B066F34 | 2 | AC | 1429 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A3ACE48C2F234 | 1 | AC | 1419 ms | 155 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
''' |
QPC003_B1 | A3AD172A4576B | 1 | AC | 1549 ms | 154 MiB | '''python
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(1)
# Write your code here:
qc.x(0)
return qc
qc = solve()
''' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.