#P10213. [CTS2024] 多方计算
[CTS2024] 多方计算
Problem Description
Abusing the judging system of this problem will result in an account ban.
Special note: To make judging work properly, please delete #include "mpc.h" at the beginning of your code and add the following code snippet:
#include <array>
struct player{
bool last_message;
std::array<int, 4096> memory;
};
int precalc(int n, int m);
bool transmit(player &player, int round, int position);
This is an interactive problem.
There are people, numbered from to . Person has an integer in .
Person wants to know the value of . To do this, they can communicate as follows:
- First, choose the number of communication seconds .
- In each of the next seconds, all simultaneously send one bit of information to .
- The message will be received before the next second begins. In particular, messages sent in the last second will not be received.
- Besides this, no other form of communication is allowed.
You need to complete this task using as few communication seconds as possible.
Implementation details
Please make sure your program starts with #include "mpc.h".
You do not need to and should not implement main. You need to implement the following two functions:
int precalc(int n, int m);
nis the number of people, andmis the value range parameter of the integers.- You need to return the number of communication seconds .
bool transmit(player &player, int round, int position);
roundis the current communication second, taking an integer value in .positionis the index of the person currently transmitting information, taking an integer value in .playeris a struct type describing the person currently transmitting. This struct is implemented inmpc.h. It contains the following two member variables:- A boolean variable
last_message, representing the information sent by the previous person in the previous second. Ifpositionis orroundis , thenlast_messageis guaranteed to be . - An integer array
memoryof length , describing the person’s “memory”.- In the
transmitfunction, this array may be modified arbitrarily. player.memorycan only be modified insidetransmit. Ifplayer.memoryis not modified intransmit, then when the same person transmits multiple times,player.memorystores the same value each time.- The initial value of
player.memoryis set by the following rules:- When
positionis not , positions to ofmemorytake values in , describing the binary representation of from low bit to high bit (i.e., the -th bit corresponds to weight ), and all other positions are . - Otherwise, all positions of the array are .
- When
- In the
- A boolean variable
- You need to return the information (one bit) that this person transmits to the next person in this second.
- When
positionis orroundis , this return value will not have any effect.
- When
After all calls to transmit end, you must ensure that in person ’s player.memory, the first positions all take values in , and the corresponding binary number is the sum of all .
Under the problem conditions and Constraints, the interaction library consumes at most seconds of time and of memory.
Using other forms of communication in the program, including but not limited to using global variables, will be considered as attacking the interaction library.
How to run the test program
A reference implementation of the interaction library, grader.cpp, is provided in the problem directory. The interaction library used in the final test is different from this implementation, so your solution must not depend on specific implementation details of the library.
You need to compile in this problem directory using the following command to obtain the executable:
g++ mpc.cpp grader.cpp -o mpc -O2 -std=c++17 -lm
The executable will read input from standard input in the following format:
- The first line contains two integers .
- The next lines each contain
01integers, from low to high, representing the binary representation of each person’s integer. The two integers in each line are separated by a space.
After reading is complete, the interaction library will first call init(n,m) once to get , and then perform rounds of calls. In round , it will call all transmit functions with , and after finishing the calls, it will update the corresponding player.last_message values.
- If , then no calls will be made, and all
player.memoryvalues remain at their initial values.
If your program runs correctly, the executable will output data in the following format:
- The first line is a string of length , representing the sum of all , output in binary from low bit to high bit.
- The second line is a string that outputs, in order, the number represented by the first positions of person ’s
player.memoryafter all interaction ends. There are no spaces between adjacent digits. - The third line: if the above two strings are different, it will tell you the answer is wrong; otherwise, it will output your score on this testdata.
This problem directory also includes sample files 1.in, 1.ans, and a sample program mpc.cpp. The sample program can pass the provided sample.
Hint
Subtasks
For all testdata, .
This problem has 10 subtasks, each worth 10 points.
| Subtask ID | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| 5 | 1000 | 3 | 10 | 500 | 1000 | 1500 | 2000 | |||
| 1 | 10 | 30 | 1000 | |||||||
Scoring
This problem is first subject to the same limits as traditional problems, e.g. a compilation error will cause the entire problem to score 0 points; runtime errors, exceeding the time limit, exceeding the memory limit, etc. will cause the corresponding test point to score 0 points.
Besides the above conditions, on a test point, if , or after all transmit calls end, the binary number corresponding to the first bits in person ’s player.memory is not the sum of all , you will get points. Otherwise, based on the value of , your score on that test point is computed according to the following table:
| Score | 1 | 2 | 3 | 4 | 6 | 8 | 10 |
Your score for a subtask is the minimum score among all test points in that subtask.
Translated by ChatGPT 5