P1423 [CF1001I] Deutsch-Jozsa algorithm
普及+
题目描述

You are given a quantum oracle - an operation on N + 1 qubits which implements a function $$f: \{0, 1\}^N \to \{0, 1\}$$. 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) = xk and $$f(x) = \sum_{i} x_i \mod 2$$) 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:

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
190190 1
样例输出
Test passed