#P11050. [IOI 2024] 消息篡改者
[IOI 2024] 消息篡改者
Background
Do not use .
Please submit in C++ 20, and paste the following at the top of your file:
#include <vector>
std::vector<bool> send_packet(std::vector<bool>);
void send_message(std::vector<bool>, std::vector<bool>);
std::vector<bool> receive_message(std::vector<std::vector<bool>>);
Problem Description
Task Description
Aisha and Basma are two friends who communicate with each other. Aisha has a message that she wants to send to Basma. The message is a sequence of bits (i.e., some 0s and 1s). Aisha communicates with Basma by sending packets. A packet is a sequence of bits, with positions indexed from to . To send the message to Basma, Aisha sends several packets.
However, a third person, Cleopatra, is sabotaging the communication between Aisha and Basma and can tamper with the sent packets. In each packet, Cleopatra can modify the bits at exactly positions. More specifically, given an array of length where each element is either or , its meaning is:
- means the bit at position can be modified by Cleopatra. We call such positions controlled by Cleopatra.
- means the bit at position cannot be modified by Cleopatra.
The array contains exactly ones and zeros. When sending the message , the set of positions controlled by Cleopatra is the same for all packets. Aisha knows exactly which positions are controlled by Cleopatra. Basma only knows that positions are controlled, but does not know which ones.
Let be the packets Aisha chooses to send (called the original packets). Let be the packets Basma receives (called the tampered packets). For each with :
- If Cleopatra cannot control the bit at position (), then Basma will receive the -th bit that Aisha sent ().
- Otherwise, if Cleopatra controls the bit at position (), then the value of is decided by Cleopatra.
After each packet is sent, Aisha immediately learns the content of the tampered packet.
After Aisha finishes sending all packets, Basma receives all tampered packets in the sending order, and she must reconstruct the original message .
Your task is to design and implement a strategy so that when Aisha sends the message to Basma, Basma can recover from the tampered packets. In particular, you need to implement two functions. The first function performs Aisha's actions: given the message and the array , send several packets to transmit the message. The second function performs Basma's actions: given several tampered packets, recover the original message .
Implementation Details
The first function you need to implement is:
void send_message(std::vector<bool> M, std::vector<bool> C)
- : an array of length , describing the message Aisha wants to send to Basma.
- : an array of length , marking the positions in a packet that are controlled by Cleopatra.
- In each test case, this function can be called at most 2100 times.
This function calls the following function to send a packet:
std::vector<bool> send_packet(std::vector<bool> A)
- : the original packet (an array of length ), representing the bits Aisha sends.
- This function returns the tampered packet , representing the bits Basma receives.
- During one call to
send_message, this function can be called at most times.
The second function you need to implement is:
std::vector<bool> receive_message(std::vector<std::vector<bool>> R)
- : an array describing several tampered packets. These packets come from the packets Aisha sent during one call to
send_message, and they are listed in Aisha's sending order. Each element of is an array of length , representing one tampered packet. - This function should return an array containing bits, equal to the original message .
- In each test case, this function may be called multiple times. For each call to
send_message, there will be exactly one corresponding call to this function. The call order ofreceive_messagedoes not have to match the order of the correspondingsend_messagecalls.
Note that in the grading system, the two functions send_message and receive_message are called in different programs.
Hint
Constraints
- .
- has exactly elements, with zeros and ones.
Subtasks and Scoring
If in any test case, the calls to the function send_packet do not follow the rules above, or the return value of some call to receive_message is not correct, then your solution gets points for that test case.
Otherwise, let be the maximum, over all test cases, of the number of times send_packet is called during one call to send_message. Let be:
- , if .
- , if .
- , if .
Then the score is computed by:
| Subtask | Score | Additional Constraints |
|---|---|---|
| 1 | ||
| 2 | No additional constraints. |
Note that in some test cases, the behavior of the grader is adaptive. This means that the return value of send_packet may depend on its input and on the return values of previous calls.
Example
Consider the following call.
send_message([0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
The message Aisha tries to send to Basma is . Bits to of the packet cannot be modified by Cleopatra, while bits to can be modified by Cleopatra.
To make this example easier to explain, we assume that Cleopatra behaves deterministically: she alternates between filling the bits she controls with and . That is, she sets the first position she controls to (position in the example), the second controlled position to (position ), the third controlled position to (position ), and so on.
One possible choice Aisha can make is to send two bits of the original message in one packet. For example, she does it as follows: she sends the first bit using the first positions she controls, and sends the second bit using the next positions she controls.
So Aisha sends the following packet:
send_packet([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Since Cleopatra can change the last bits, Aisha decides to set them arbitrarily, because they may be overwritten. With Cleopatra's assumed strategy, the function returns:
$[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]$.
Aisha decides to send the last two bits of in the second packet, similarly to before:
send_packet([1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
With Cleopatra's assumed strategy, the function returns:
$[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]$.
Aisha could send more packets, but she does not.
Then the grader makes the following call:
receive_message([[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]])
Basma recovers the message as follows. From each packet, she extracts the first bit that appears twice consecutively, and the last bit that appears twice consecutively. That is, she extracts two bits from the first packet, and two bits from the second packet. Putting them together, she recovers the message , which is the correct return value for the call to receive_message.
It can be proven that under the assumed strategy of Cleopatra, for a message of length , no matter what the value of is, Basma can correctly recover in this way. However, in general, this is not correct.
Sample Grader
The sample grader is not adaptive. Cleopatra behaves deterministically and alternates between filling the bits she controls with and , just like she did in the example.
Input format: The first line of input contains an integer , specifying the number of test cases. Then there are test cases, each described in the following format:
S
M[0] M[1] ... M[S-1]
C[0] C[1] ... C[30]
Output format: The sample grader outputs the results for the test cases in the input order, in the following format:
K L
D[0] D[1] ... D[L-1]
Here, is the number of calls to send_packet, is the message returned by receive_message, and is its length.
Translated by ChatGPT 5