I. Deutsch-Jozsa algorithm

Codeforces
IDCF1001I
Time1000ms
Memory256MB
Difficulty
English · Original
Chinese · Translation
Formal · Original
You are given a quantum oracle - an operation on _N_ + 1 qubits which implements a function . You are guaranteed that the function _f_ implemented by the oracle is either constant (returns 0 on all inputs or 1 on all inputs) or balanced (returns 0 on exactly one half of the input domain and 1 on the other half). There are only two possible constant functions: _f_(_x_) = 0 and _f_(_x_) = 1. The functions implemented by oracles in the two previous problems (_f_(_x_) = _x__k_ and ) are examples of balanced functions. Your task is to figure out whether the function given by the oracle is constant. Your code is allowed to call the given oracle only once. ## Input You have to implement an operation which takes the following inputs: * an integer _N_ - the number of qubits in the oracle input, * an oracle _Uf_, implemented as an operation with signature _((Qubit\[\], Qubit) => ())_, i.e., an operation which takes as input an array of qubits and an output qubit and has no output. The return of your operation is a Boolean value: true if the oracle implements a constant function and false otherwise. Your code should have the following signature: namespace Solution { open Microsoft.Quantum.Primitive; open Microsoft.Quantum.Canon; operation Solve (N : Int, Uf : ((Qubit\[\], Qubit) => ())) : Bool { body { // your code here } } } [samples]
你被给予一个量子预言机——一个作用于 #cf_span[N + 1] 个量子比特上的操作,用于实现一个函数。你保证该预言机实现的函数 #cf_span[f] 要么是常数函数(对所有输入返回 0 或对所有输入返回 1),要么是平衡函数(对输入域中恰好一半的输入返回 0,另一半返回 1)。 只有两种可能的常数函数:#cf_span[f(x) = 0] 和 #cf_span[f(x) = 1]。前两个问题中预言机实现的函数(#cf_span[f(x) = xk] 和 )是平衡函数的示例。 你的任务是判断该预言机给出的函数是否为常数函数。你的代码只能调用给定的预言机一次。 你需要实现一个操作,该操作接收以下输入: 你的操作返回一个布尔值:如果预言机实现的是常数函数则返回 true,否则返回 false。 你的代码应具有以下签名: ## Input 你需要实现一个操作,该操作接收以下输入:一个整数 #cf_span[N] —— 预言机输入的量子比特数,一个预言机 #cf_span[Uf],其作为具有签名 _((Qubit[], Qubit) => ())_ 的操作实现,即一个接收量子比特数组和一个输出量子比特作为输入、无返回值的操作。你的操作返回一个布尔值:如果预言机实现的是常数函数则返回 true,否则返回 false。你的代码应具有以下签名:namespace Solution { open Microsoft.Quantum.Primitive; open Microsoft.Quantum.Canon; operation Solve (N : Int, Uf : ((Qubit[], Qubit) => ())) : Bool { body { // your code here } }} [samples]
**Definitions** Let $ N \in \mathbb{Z}^+ $. Let $ f: \{0,1\}^N \to \{0,1\} $ be a function implemented by a quantum oracle. Let $ \mathcal{O}_f $ be the unitary operator acting on $ \mathbb{C}^{2^{N+1}} $ such that: $$ \mathcal{O}_f |x\rangle |y\rangle = |x\rangle |y \oplus f(x)\rangle, \quad \forall x \in \{0,1\}^N, y \in \{0,1\}. $$ **Constraints** The function $ f $ is guaranteed to be either: - **Constant**: $ f(x) = 0 $ for all $ x \in \{0,1\}^N $, or $ f(x) = 1 $ for all $ x \in \{0,1\}^N $; - **Balanced**: $ |\{x \in \{0,1\}^N : f(x) = 0\}| = |\{x \in \{0,1\}^N : f(x) = 1\}| = 2^{N-1} $. **Objective** Design a quantum algorithm that, using a single query to $ \mathcal{O}_f $, outputs: $$ \begin{cases} \texttt{true} & \text{if } f \text{ is constant}, \\ \texttt{false} & \text{if } f \text{ is balanced}. \end{cases} $$ The algorithm must act on $ N+1 $ qubits, initialized to $ |0\rangle^{\otimes N} |1\rangle $, apply Hadamard gates to all qubits, query $ \mathcal{O}_f $, apply Hadamard gates to the first $ N $ qubits, and measure the first $ N $ qubits. Return **true** if the measurement outcome is $ |0\rangle^{\otimes N} $, **false** otherwise.
API Response (JSON)
{
  "problem": {
    "name": "I. Deutsch-Jozsa algorithm",
    "description": {
      "content": "You are given a quantum oracle - an operation on _N_ + 1 qubits which implements a function . You are guaranteed that the function _f_ implemented by the oracle is either constant (returns 0 on all in",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF1001I"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a quantum oracle - an operation on _N_ + 1 qubits which implements a function . You are guaranteed that the function _f_ implemented by the oracle is either constant (returns 0 on all in...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "你被给予一个量子预言机——一个作用于 #cf_span[N + 1] 个量子比特上的操作,用于实现一个函数。你保证该预言机实现的函数 #cf_span[f] 要么是常数函数(对所有输入返回 0 或对所有输入返回 1),要么是平衡函数(对输入域中恰好一半的输入返回 0,另一半返回 1)。\n\n只有两种可能的常数函数:#cf_span[f(x) = 0] 和 #cf_span[f(x) = 1]。前两个...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $. Let $ f: \\{0,1\\}^N \\to \\{0,1\\} $ be a function implemented by a quantum oracle.  \nLet $ \\mathcal{O}_f $ be the unitary operator acting on $ \\mathbb{C}^{2^...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments