#P11050. [IOI 2024] 消息篡改者

[IOI 2024] 消息篡改者

Background

Do not use #include "message.h"\texttt{\#include "message.h"}.

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 MM that she wants to send to Basma. The message is a sequence of SS bits (i.e., some 0s and 1s). Aisha communicates with Basma by sending packets. A packet is a sequence of 3131 bits, with positions indexed from 00 to 3030. To send the message MM 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 1515 positions. More specifically, given an array CC of length 3131 where each element is either 00 or 11, its meaning is:

  • C[i]=1C[i] = 1 means the bit at position ii can be modified by Cleopatra. We call such positions controlled by Cleopatra.
  • C[i]=0C[i] = 0 means the bit at position ii cannot be modified by Cleopatra.

The array CC contains exactly 1515 ones and 1616 zeros. When sending the message MM, the set of positions controlled by Cleopatra is the same for all packets. Aisha knows exactly which 1515 positions are controlled by Cleopatra. Basma only knows that 1515 positions are controlled, but does not know which ones.

Let AA be the packets Aisha chooses to send (called the original packets). Let BB be the packets Basma receives (called the tampered packets). For each ii with 0i<310 \leq i < 31:

  • If Cleopatra cannot control the bit at position ii (C[i]=0C[i]=0), then Basma will receive the ii-th bit that Aisha sent (B[i]=A[i]B[i]=A[i]).
  • Otherwise, if Cleopatra controls the bit at position ii (C[i]=1C[i]=1), then the value of B[i]B[i] 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 MM.

Your task is to design and implement a strategy so that when Aisha sends the message MM to Basma, Basma can recover MM from the tampered packets. In particular, you need to implement two functions. The first function performs Aisha's actions: given the message MM and the array CC, send several packets to transmit the message. The second function performs Basma's actions: given several tampered packets, recover the original message MM.

Implementation Details

The first function you need to implement is:

void send_message(std::vector<bool> M, std::vector<bool> C)
  • MM: an array of length SS, describing the message Aisha wants to send to Basma.
  • CC: an array of length 3131, 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)
  • AA: the original packet (an array of length 3131), representing the bits Aisha sends.
  • This function returns the tampered packet BB, representing the bits Basma receives.
  • During one call to send_message, this function can be called at most 100100 times.

The second function you need to implement is:

std::vector<bool> receive_message(std::vector<std::vector<bool>> R)
  • RR: 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 RR is an array of length 3131, representing one tampered packet.
  • This function should return an array containing SS bits, equal to the original message MM.
  • 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 of receive_message does not have to match the order of the corresponding send_message calls.

Note that in the grading system, the two functions send_message and receive_message are called in different programs.

Hint

Constraints

  • 1S10241 \leq S \leq 1024.
  • CC has exactly 3131 elements, with 1616 zeros and 1515 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 00 points for that test case.

Otherwise, let QQ be the maximum, over all test cases, of the number of times send_packet is called during one call to send_message. Let XX be:

  • 11, if Q66Q \leq 66.
  • 0.95Q660.95 ^ {Q - 66}, if 66<Q10066 < Q \leq 100.
  • 00, if 100<Q100 < Q.

Then the score is computed by:

Subtask Score Additional Constraints
1 10X10 \cdot X S64S \leq 64
2 90X90 \cdot X 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 [0,1,1,0][0, 1, 1, 0]. Bits 00 to 1515 of the packet cannot be modified by Cleopatra, while bits 1616 to 3030 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 00 and 11. That is, she sets the first position she controls to 00 (position 1616 in the example), the second controlled position to 11 (position 1717), the third controlled position to 00 (position 1818), 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 88 positions she controls, and sends the second bit using the next 88 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 1515 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 MM 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 MM 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 [0,1][0, 1] from the first packet, and two bits [1,0][1, 0] from the second packet. Putting them together, she recovers the message [0,1,1,0][0, 1, 1, 0], 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 44, no matter what the value of CC is, Basma can correctly recover MM 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 00 and 11, just like she did in the example.

Input format: The first line of input contains an integer TT, specifying the number of test cases. Then there are TT 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 TT test cases in the input order, in the following format:

K L
D[0]  D[1]  ...  D[L-1]

Here, KK is the number of calls to send_packet, DD is the message returned by receive_message, and LL is its length.

Translated by ChatGPT 5