PDP-38 (2026) - Phase B - 2 (commsystem)
View as PDFCommunication System
After several incidents of miscommunication with his waiters, Takis installed a new electronic system in his pizzeria so that they could transmit orders from the serving area to the kitchen. The system allows waiters to send orders to Takis encoded as binary strings, that is, strings consisting of and
(e.g. "
").
Let ,
,
,
be a sequence consisting of
positive integers.
We will say that the sequence
is a pyramid if there exists a position
(with
) such that:
, for every
with
,
, for every
with
.
In some strange way (which does not concern us), every order at the pizzeria is represented as a pyramid. Your task is to create a communication protocol between the waiters and Takis.
This is a "communication" problem. This means that your code will be executed twice for each test case:
- the first time (as the waiters), with the orders as input, in order to "encode" them into binary strings that can be sent through the system,
- the second time (as Takis), with the binary strings encoded during the first execution as input, in order to "decode" them and reconstruct the orders as pyramids.
Your code is considered correct for an order if the pyramid it prints during the second execution is identical to the one it received as input during the first execution, and it is considered correct for a test case if it is correct for all the orders it contains. Read the following carefully to understand how the input and output work, as well as how scoring is performed (it depends on the lengths of the binary strings you send through the system).
Problem
Write a program in C++ that reads the input data from the file commsystem.in and prints the results to the file commsystem.out.
Input Files (commsystem.in)
The first line contains an integer , which is either equal to
or equal to
.
The second line contains an integer
: the number of orders.
If , you take the role of the waiters.
The next
orders follow, each consisting of two lines.
The first line of each order contains an integer
: the size of the corresponding pyramid.
The second line of the order contains
integers
,
,
,
: the elements of the pyramid.
If , you take the role of Takis.
The next
messages follow, each consisting of one line containing a binary string.
It is guaranteed that the binary strings were produced by running your program on some orders with
.
Output Files (commsystem.out)
If , the output must contain
lines.
For each order, the corresponding line must contain a non-empty binary string that encodes the corresponding input pyramid.
If , the output must contain
lines.
Each order must correspond to two lines: the first line must contain an integer, the size
of the pyramid represented by the binary string, and the second line must contain
integers, the elements of the pyramid.
Sample Input - Output Files:
First execution:
Input:
1
2
5
1 4 8 11 3
3
1 2 3
Output:
0011010
111
Second execution:
Input:
2
2
0011010
111
Output:
5
1 4 8 11 3
3
1 2 3
Explanation:
During its first execution, our program chooses to encode the pyramid as the binary string "
" and
as "
".
Note: This encoding is arbitrary; your program may choose any encoding format it wants.
During its second execution, our program receives as input the binary strings produced during the first execution and manages to decode them and reconstruct the original orders received by the waiters. Thus, our program is considered correct for this test case.
Constraints
- \(1 \\e T \le 100.000\)
- Every given order is a pyramid.
Subtasks:
Let be the maximum length of a binary string sent by your program during its first execution, considering all orders across all test cases of the given subtask.
- (21 points) You must have
.
- (23 points) Either
or
, and you must have
.
- (27 points) You must have
.
- (29 points) You must have
.
Notes:
- Formatting: In both the input and the output, each line ends with a
newlinecharacter. - Maximum execution time:
sec. for each of the two executions.
- Maximum available memory:
MB.
Warning: The answer may exceed and, in general, you may need to perform operations with numbers larger than those that can be represented by the basic
int type.
Also, make sure to read the input and print the output efficiently in problems that require it.
Comments