A2. Generate superposition of zero state and a basis state

Codeforces
IDCF1002A2
Time1000ms
Memory256MB
Difficulty
English · Original
Chinese · Translation
Formal · Original
You are given _N_ qubits (1 ≤ _N_ ≤ 8) in zero state . You are also given a bitstring _bits_ which describes a non-zero basis state on _N_ qubits . Your task is to generate a state which is an equal superposition of and the given basis state: You have to implement an operation which takes the following inputs: * an array of qubits _qs_, * an arrays of boolean values _bits_ representing the basis state . This array will have the same length as the array of qubits. The first element of this array _bits_\[0\] will be _true_. The operation doesn't have an output; its "output" is the state in which it leaves the qubits. An array of boolean values represents a basis state as follows: the _i_\-th element of the array is true if the _i_\-th qubit is in state , and false if it is in state . For example, array _\[true; false\]_ describes 2-qubit state , and in this case the resulting state should be . Your code should have the following signature: namespace Solution { open Microsoft.Quantum.Primitive; open Microsoft.Quantum.Canon; operation Solve (qs : Qubit\[\], bits : Bool\[\]) : () { body { // your code here } } } [samples]
给定 #cf_span[N] 个量子比特(#cf_span[1 ≤ N ≤ 8]),初始处于零态。同时给定一个比特串 #cf_span[bits],它描述了 #cf_span[N] 个量子比特上的一个非零基态。 你的任务是生成一个状态,该状态是 和给定基态的等权叠加: 你需要实现一个操作,它接收以下输入: 该操作没有输出;其“输出”是它作用后量子比特所处的状态。 一个布尔值数组表示一个基态的方式如下:数组的第 #cf_span[i] 个元素为 true 表示第 #cf_span[i] 个量子比特处于 状态,false 表示处于 状态。例如,数组 _[true; false]_ 描述 2 量子比特态 ,此时最终状态应为 。 你的代码应具有以下签名: [samples]
**Definitions** Let $ N \in \mathbb{Z} $, $ 1 \leq N \leq 8 $, be the number of qubits. Let $ \mathbf{b} = (b_1, b_2, \dots, b_N) \in \{0,1\}^N $ be a non-zero bitstring representing a computational basis state $ |\mathbf{b}\rangle = |b_1 b_2 \dots b_N\rangle $. Let $ |0^N\rangle = |0\rangle^{\otimes N} $ denote the all-zero state. **Constraints** - $ \mathbf{b} \neq \mathbf{0} $ (i.e., at least one $ b_i = 1 $). **Objective** Implement a quantum operation that transforms the initial state $ |0^N\rangle $ into the normalized superposition: $$ |\psi\rangle = \frac{1}{\sqrt{2}} \left( |0^N\rangle + |\mathbf{b}\rangle \right) $$
API Response (JSON)
{
  "problem": {
    "name": "A2. Generate superposition of zero state and a basis state",
    "description": {
      "content": "You are given _N_ qubits (1 ≤ _N_ ≤ 8) in zero state . You are also given a bitstring _bits_ which describes a non-zero basis state on _N_ qubits . Your task is to generate a state which is an equal ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF1002A2"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given _N_ qubits (1 ≤ _N_ ≤ 8) in zero state . You are also given a bitstring _bits_ which describes a non-zero basis state on _N_ qubits .\n\nYour task is to generate a state which is an equal ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给定 #cf_span[N] 个量子比特(#cf_span[1 ≤ N ≤ 8]),初始处于零态。同时给定一个比特串 #cf_span[bits],它描述了 #cf_span[N] 个量子比特上的一个非零基态。\n\n你的任务是生成一个状态,该状态是  和给定基态的等权叠加:\n\n你需要实现一个操作,它接收以下输入:\n\n该操作没有输出;其“输出”是它作用后量子比特所处的状态。\n\n一个布尔值数组表示一个基...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z} $, $ 1 \\leq N \\leq 8 $, be the number of qubits.  \nLet $ \\mathbf{b} = (b_1, b_2, \\dots, b_N) \\in \\{0,1\\}^N $ be a non-zero bitstring representing a computation...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments