Aisha and Basma are two friends who correspond with each other.
Aisha has a message
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
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
Let
- 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
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 ofsend_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 onesend_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 send_packet
among all invocations of send_message
over all test cases.
Also let
, 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
For the sake of this example,
let us assume that Cleopatra fills consecutive bits she controls
with alternating
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
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
Aisha decides to send the last two bits of
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 receive_message
.
It can be shown that with the assumed strategy of Cleopatra and for messages of length
Sample Grader
The sample grader is not adaptive.
Instead, Cleopatra fills consecutive bits she controls with alternating
Input format: The first line of the input contains an integer
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
K L
D[0] D[1] ... D[L-1]
Here, send_packet
,
receive_message
and
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
How can
2100 * 32 * (1024 / 16) * 3 ~ 1e7
vector operations TLE in 3 seconds? https://dmoj.ca/src/6866077 My code passes comfortably on codeforces in under 500 ms