QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 256 MB Puntuación total: 100 Comunicación

#9688. Communication

Estadísticas

There are several nodes, each initially storing a number $a_i \in \{0, 1\}$. They want to know the numbers stored by every other node through $K$ rounds of communication.

At the beginning of each round of communication, each node $i$ chooses a number $c_{i,j} \in \{0, 1\}$ for every node $j$, representing that it will send the number $c_{i,j}$ to node $j$. At the end of this round, node $j$ receives the sum of the numbers sent to it by all nodes. Specifically, node $j$ receives a number $s_j = \sum_i c_{i,j}$.

Given $K$, you need to find a value $N$ as large as possible such that after $K$ rounds of communication, every node can know the numbers stored by all nodes.

Implementation Details

You do not need to, and should not, implement the main function.

You must ensure that your submitted program includes the header file message.h. You can include it at the beginning of your program:

#include "message.h"

You need to implement the following functions:

int init(int K);
  • This function receives the total number of communication rounds $K$. It is guaranteed that $1 \le K \le 7$.
  • This function needs to return the number of nodes $N$ you choose. You must ensure $1 \le N \le 31$.
  • For each execution of the code, it is guaranteed that this function will be called exactly once by the interactor before any send function call.
unsigned int send(int K, int N, int round, int number, const std::vector<int>& received);
  • This function receives the total number of communication rounds $K$, the number of nodes $N$ returned by your init function, the current round of communication round, the index of the node you are currently implementing number, and the numbers received by this node in previous rounds of communication. Here, received[0] represents the number initially stored by this node, and received[i] ($1 \le i < round$) represents the number received by this node at the end of the $i$-th round of communication. It is guaranteed that $1 \le K \le 7$, $1 \le round \le K + 1$, $0 \le number < N$, and the length of received is round.
  • If $1 \le round \le K$, you need to return an unsigned 32-bit integer $x$ representing the numbers sent by node number to all nodes in this round of communication, where the $i$-th bit of $x$ is the number sent by node number to node $i$, with higher bits padded with 0.
  • If $round = K + 1$, you need to return an unsigned 32-bit integer $x$ representing the numbers stored by every node as determined by node number after $K$ rounds of communication, where the $i$-th bit of $x$ is the number stored by the node with index $i$, with higher bits padded with 0.
  • For each execution of the code, it is guaranteed that this function will be called by the interactor no more than $3 \times 10^4$ times.

Note: You must ensure that for any two function calls (including init and send) with the same input parameters, the return value is also the same; otherwise, your program will be directly judged as incorrect.

The problem guarantees that under the specified limits, the interactor's running time in each execution will not exceed 100 ms; the memory used by the interactor is fixed and does not exceed 64 MiB. This means that in each execution, your code can use at least 900 ms of time and 448 MiB of space.

Subtasks

For all test data, it is guaranteed that $1 \le K \le 7$, and for each execution of the code, send will be called by the interactor no more than $3 \times 10^4$ times.

Test Case ID Score $K =$
1 5 1
2 5 2
3 10 3
4 15 4
5 15 5
6 20 6
7 30 7

Scoring

Note: You should not obtain internal information of the interactor through illegal means, such as attempting to directly read values stored in the interactor or interacting directly with standard input/output streams. Such behavior will be considered cheating. The final evaluation interactor differs from the sample interactor, so your solution should not rely on the interactor's implementation.

This problem is subject to the same restrictions as traditional problems. For example, compilation errors will result in 0 points for the entire problem, while runtime errors, time limit exceeded, or memory limit exceeded will result in 0 points for the corresponding test case. You may only access variables and their corresponding memory space defined by yourself or provided by the interactor; attempting to access other memory may lead to compilation or runtime errors.

Based on the above conditions, the score obtained by the program in each test case is calculated as follows: If the return value is different for any two calls to the same function with the same input parameters, you receive 0 points. If the numbers stored by each node determined after $K$ rounds of communication are different from the numbers initially stored by each node, you receive 0 points. * Otherwise, let $N$ be the result obtained by calling the init() function. The score for this test case is $s \times 0.7^{\max(C(K)-N, 0)}$, where $s$ is the score for that test case, and $C(K)$ is calculated as shown in the table below:

$K =$ 1 2 3 4 5 6 7
$C(K) =$ 2 4 6 11 14 21 25

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.