NOI '21 P4 - Quantum Communication

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 3.0s
Memory limit: 384M

Problem type

Alice and Bob are engaging in quantum communication. Their language of communication is a dictionary S of size n. In the dictionary, a word si (1in) may be represented by a 256-bit binary string. In this problem, si may be generated by calling function gen. The contestants may refer to gen.cpp, and the parameters n,a1,a2 will be specified by the test cases.

Alice and Bob will communicate for m rounds next. In each round, Alice will send bob exactly one word in the dictionary. However, their communication channel is not reliable and may be disturbed by noise. More formally, for the i-th round of communication, suppose the word Alice wants to send is xi, then at most ki bits of the binary string will flip. In other words, suppose the binary string Bob receives is yi, then yi is different from xi for at most ki positions. yi does not have to be in dictionary S.

At the same time, Bob knows Eve has invaded the communication channel and is going to manipulate the communication between Alice and Bob. Eve will replace the binary string Bob is going into receive with an arbitrary 256-bit binary string, and the arbitrary 256-bit binary string does not have to be in the dictionary. Eve does not have to manipulate all rounds of communication.

Now Bob asks you for help, and you need to determine whether it is possible that a round of communication is not manipulated by Eve given the string Bob received and the threshold for noise disturbance ki (0ki15). In other words, you need to check whether the binary string Bob received can be obtained by flipping at most ki bits of a word in the dictionary. If it is possible that the round of communication is not manipulated by Eve, output 1. Otherwise, output 0. Bob trusts your ability, so you need to answer the queries online. For the specifics, see the input section.

To save the time spent on I/O, the strings Bob received are given by 64-bit hexadecimal strings. The hexadecimal strings contain numerals 0-9 and upper-case English letters A-F. A-F represents 10-15 in that order. A hexadecimal string may be converted to a binary string bit by bit. For example, 5 will correspond to 0101, A will correspond to 1010, and C will correspond to 1100.

Input Specification

The first line of the input contains four nonnegative integers n,m,a1,a2 denoting the size of the dictionary, the number of rounds of communication, and the initial values of parameters a1 and a2 for the function gen. Contestants need to generate the dictionary using the gen function mentioned in the problem statement. Contestants may copy and use the code in gen.cpp. The Boolean array s[N+1][256] is just the list of all words.

For the next m lines, each line contains a hexadecimal string of length 64 and a nonnegative integer ki denoting the final binary string Bob received in round i and the threshold for noise disturbance.

To make sure contestants are answering the queries online, after the contestants recover the 256-bit binary string based on the hexadecimal string, contestants need to perform XOR operation with lastans bitwise to recover the real binary string Bob received in the round. lastans {0,1} denotes the answer to the query last round. Before the first round, the initial value of lastans is 0.

Notice: when reading or writing unsigned long long variables using scanf or printf, use llu.

Output Specification

The output consists of m lines. Each line contains an integer 0 or 1 denoting the answer to the query.

Sample

For convenience, we will give the words in the dictionary explicitly, reduce the word length to 4, and allow offline answers to the queries.

Suppose the dictionary size is n=2. The words are 1010 and 0111.

For query B = 1011 and k1=1, the output shall be 1 since B may be obtained by flipping the 4-th bit of 1010.

For query B = 0001 and k2=2, the output shall be 1 since 0001 may be obtained by flipping the second and the third bit of 0111.

For query B = 0001 and k3=1, the output shall be 0.

The remaining samples can be found here.

Constraints

For all test cases, 1n4×105, 1m1.2×105, 0k15, and a1,a2 are uniformly random among [0,2641].

Test case n= m= ki Additional Constraints
1 10 2 None.
2 500 15
3 1000 0
4 2000 2
5 5000 15
6 10000
7 20000
8 100000 1
9 400000 120000
10 50000 2
11 70000 3
12 100000 2
13 30000 5
14 60000 4
15 120000 5
16 60000 8 The query strings are generated randomly.
17 120000 12
18 400000 100000 15
19 30000 7 None.
20 60000 9
21 90000 11
22 200000 120000 12
23 400000 80000 15
24 400000 100000 15
25 400000 120000 15

Comments

There are no comments at the moment.