Aisha and Basma are two friends who correspond with each other. Aisha has a message , which is a sequence of bits (i.e., zeroes or ones), that she would like to send to Basma. Aisha communicates with Basma by sending her packets. A packet is a sequence of bits indexed from to . Aisha would like to send the message to Basma by sending her some number of packets.
Unfortunately, Cleopatra compromised the communication between Aisha and Basma and is able to taint the packets. That is, in each packet Cleopatra can modify bits on exactly indices. Specifically, there is an array of length , in which every element is either or , with the following meaning:
- indicates that the bit with index can be changed by Cleopatra. We call these indices controlled by Cleopatra.
- indicates that bit with index cannot be changed by Cleopatra.
The array contains precisely ones and zeroes. While sending the message , the set of indices controlled by Cleopatra stays the same for all packets. Aisha knows precisely which indices are controlled by Cleopatra. Basma only knows that indices are controlled by Cleopatra, but she does not know which indices.
Let be a packet that Aisha decides to send (which we call the original packet). Let be the packet that is received by Basma (which we call the tainted packet). For each , such that :
- if Cleopatra does not control the bit with index (), Basma receives bit as sent by Aisha (),
- otherwise, if Cleopatra controls the bit with index (), the value of is decided by Cleopatra.
Immediately after sending each packet, Aisha learns what the corresponding tainted packet is.
After Aisha sends all the packets, Basma receives all the tainted packets in the order they were sent and has to reconstruct the original message .
Your task is to devise and implement a strategy that would allow Aisha to send the message to Basma, so that Basma can recover from the tainted packets. Specifically, you should implement two procedures. The first procedure performs the actions of Aisha. It is given a message and the array , and should send some packets to transfer the message to Basma. The second procedure performs the actions of Basma. It is given the tainted packets and should recover the original message .
Implementation Details
The first procedure you should implement is:
void send_message(std::vector<bool> M, std::vector<bool> C)
- : an array of length describing the message that Aisha wants to send to Basma.
- : an array of length indicating the indices of bits controlled by Cleopatra.
- This procedure may be called at most 2100 times in each test case.
This procedure should call the following procedure to send a packet:
std::vector<bool> send_packet(std::vector<bool> A)
- : an original packet (an array of length ) representing the bits sent by Aisha.
- This procedure returns a tainted packet representing the bits that will be received by Basma.
- This procedure can be called at most times
in each invocation of
send_message
.
The second procedure you should implement is:
std::vector<bool> receive_message(std::vector<std::vector<bool>> R)
- : an array describing the tainted packets.
The packets originate from packets sent by Aisha in one
send_message
call and are given in the order they were sent by Aisha. Each element of is an array of length , representing a tainted packet. - This procedure should return an array of bits that is equal to the original message .
- This procedure may be called multiple times in each test case,
exactly once for each corresponding
send_message
call. The order ofreceive_message
procedure calls is not necessarily the same as the order of the correspondingsend_message
calls.
Note that in the grading system the send_message
and receive_message
procedures are called in two separate programs.
Constraints
- has exactly elements, out of which are equal to and are equal to .
Subtasks and Scoring
If in any of the test cases,
the calls to the procedure send_packet
do not conform to the rules mentioned above,
or the return value of any of the calls to procedure receive_message
is incorrect,
the score of your solution for that test case will be .
Otherwise, let be the maximum number of calls to the procedure send_packet
among all invocations of send_message
over all test cases.
Also let be equal to:
- , if
- , if
Then, the score is calculated as follows:
Subtask | Score | Additional Constraints |
---|---|---|
1 | ||
2 | No additional constraints. |
Note that in some cases the behaviour of the grader can be adaptive.
This means that the values returned by send_packet
may depend not just on its input arguments but also on many other things,
including the inputs and return values of the prior calls to this procedure
and pseudo-random numbers generated by the grader.
The grader is deterministic in the sense that if you run it twice
and in both runs you send the same packets, it will make the same changes to them.
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 that Aisha tries to send to Basma is . The bits with indices from to cannot be changed by Cleopatra, while the bits with indices from to can be changed by Cleopatra.
For the sake of this example, let us assume that Cleopatra fills consecutive bits she controls with alternating and , i.e. she assigns to the first index she controls (index in our case), to the second index she controls (index ), to the third index she controls (index ), and so on.
Aisha can decide to send two bits from the original message in one packet as follows: she will send the first bit at the first indices she controls and the second bit at the following indices she controls.
Aisha then chooses to send 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])
Note that Cleopatra can change bits with the last indices, so Aisha can set them arbitrarily, as they might be overwritten. With the assumed strategy of Cleopatra, the procedure returns: .
Aisha decides to send the last two bits of in the second packet in a similar way as 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 the assumed strategy of Cleopatra, the procedure returns: .
Aisha can send more packets, but she chooses not to.
The grader then makes the following procedure 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 message as follows.
From each packet she takes the first bit that occurs twice in a row,
and the last bit that occurs twice in a row.
That is, from the first packet, she takes bits , and from the second
packet she takes bits .
By putting them together, she recovers the message ,
which is the correct return value for this call to receive_message
.
It can be shown that with the assumed strategy of Cleopatra and for messages of length , this approach of Basma correctly recovers , regardless of the value of . However, it is not correct in the general case.
Sample Grader
The sample grader is not adaptive. Instead, Cleopatra fills consecutive bits she controls with alternating and bits, as described in the example above.
Input format: The first line of the input contains an integer , specifying the number of scenarios. scenarios follow. Each of them is provided in the following format:
S
M[0] M[1] ... M[S-1]
C[0] C[1] ... C[30]
Output format: The sample grader writes the result of each of the scenarios in the same order as they are provided in the input 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.
Time and Memory Limit Computation
A submission's displayed execution time is calculated as the sum of the execution times of both programs. However, a submission will be accepted if both programs execute under the time limit: for example, if the first program executes in 2.5s
and the second program executes in 1.6s
, the submission will not TLE, and the time displayed will be 4.1s
.
A submission's memory usage is the maximum of the memory usages of both programs.
Attachment Package
The sample grader along with sample test cases are available here.
Comments