Message
문제
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 0 ≤ i < 31:
- 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 .