P563 [CF1002C2] Distinguish zero state and plus state without errors
提高-
题目描述

You are given a qubit which is guaranteed to be either in $$| 0 \rangle$$ state or in $${ \left| + \right\rangle } = { \frac { 1 } { \sqrt { 2 } } } ( { \left| 0 \right\rangle } + { \left| 1 \right\rangle } )$$ state.

Your task is to perform necessary operations and measurements to figure out which state it was and to return 0 if it was a $$| 0 \rangle$$ state, 1 if it was $$|+\rangle$$ state or -1 if you can not decide, i.e., an "inconclusive" result. The state of the qubit after the operations does not matter.

Note that these states are not orthogonal, and thus can not be distinguished perfectly. In each test your solution will be called 10000 times, and your goals are:

  • never give 0 or 1 answer incorrectly (i.e., never return 0 if input state was $$|+\rangle$$ and never return 1 if input state was $$| 0 \rangle$$),
  • give -1 answer at most 80% of the times,
  • correctly identify $$| 0 \rangle$$ state at least 10% of the times,
  • correctly identify $$|+\rangle$$ state at least 10% of the times.

In each test $$| 0 \rangle$$ and $$|+\rangle$$ states will be provided with 50% probability.

You have to implement an operation which takes a qubit as an input and returns an integer.

Your code should have the following signature:

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1
样例输出
Test passed