QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Interactive

#4537. King

Statistics

This is an interactive problem.

The Flea King is leading four hundred million fleas to build a computer.

We assign each flea an integer ID starting from $0$.

Since the civilization of the Flea Kingdom is underdeveloped, each flea can only store a value of $0$ or $1$. For the $i$-th flea, this value is denoted as $v_i$.

For all fleas with an ID less than $2n$, their values are determined by the Flea King. That is, these $2n$ values can be considered as the input.

We define: \begin{equation} F(a,b,f) = \left \lfloor \frac{f}{2 ^ {2 a + b}} \right \rfloor \mod 2 \end{equation}

For each flea with an ID greater than or equal to $2n$, let its ID be $i$. You need to specify three parameters $a_i, b_i, f_i$ ($0 \le a_i < i, 0 \le b_i < i, 0 \le f_i < 16$), such that: \begin{equation} v_i = F \left ( v_{a_i}, v_{b_i}, f_i \right ) = \left \lfloor \frac{f_i}{2 ^ {2 v_{a_i} + v_{b_i} }} \right \rfloor \mod 2 \end{equation} We say that the $i$-th flea depends on the $a_i$-th and $b_i$-th fleas (note that $a_i$ can be equal to $b_i$).

Several examples of $F$ are given below: - $F(0, 0, 14) = 0, F(0, 0, 8) = 0, F(0, 0, 6) = 0$ - $F(0, 1, 14) = 1, F(0, 1, 8) = 0, F(0, 1, 6) = 1$ - $F(1, 0, 14) = 1, F(1, 0, 8) = 0, F(1, 0, 6) = 1$ - $F(1, 1, 14) = 1, F(1, 1, 8) = 1, F(1, 1, 6) = 0$

Initially (at time $0$), the values of all fleas with IDs less than $2n$ are determined simultaneously. Then, for each flea with an ID greater than or equal to $2n$, its value is determined immediately after the values of the fleas it depends on are determined. Because the information technology of the Flea Kingdom is underdeveloped, it takes 1 hour for each flea to determine its value (note that multiple fleas can determine their values simultaneously).

Below is an example: (id represents the ID, t represents the time when the flea's value is determined, and arrows represent the dependency relationship)

Example

We can treat the values of the fleas with IDs less than $2n$ as two $n$-bit binary numbers $\mathrm{A}$ and $\mathrm{B}$, where $\mathrm{A} = (v_{n-1} \ v_{n-2} \ \cdots \ v_0)_2$ and $\mathrm{B} = (v_{2n-1} \ v_{2n-2} \ \cdots \ v_{n})_2$. The Flea King wants to perform some operations on $\mathrm{A}$ and $\mathrm{B}$ to obtain an $n$-bit binary number and represent it using $n$ fleas.

Since the Flea King also has to take the fleas to a ball, the number of fleas you can use and the time allowed are limited. Specifically, you can use at most $\mathrm{M}$ fleas, and you are required to specify $n$ fleas in order such that within $\mathrm{T}$ hours, the values of all fleas you use can be determined, and the binary number represented by the values of the specified $n$ fleas is the answer sought by the Flea King.

As a reward, the Flea King intends to give you a UOJ pillow. The first contestant to pass the last test case will receive a UOJ pillow. If no contestant passes the last test case, the first contestant to achieve the highest score on this problem will receive a UOJ pillow.

Task

You need to write a function build_computer to help the Flea King build the computer.

  • build_computer(task_id, n, M, T)
    • task_id: Subtask ID
    • n: The number of bits of the input $\mathrm{A}$ and $\mathrm{B}$
    • M: The maximum number of fleas that can be used, excluding those with IDs less than $2n$
    • T: The time limit in hours within which the values of all fleas you use must be determined

You can call the function add_flea(a, b, f), which adds a flea. For the $i$-th call, the ID of the added flea is $2n + i - 1$, and $a_{2n+i-1}, b_{2n+i-1}, f_{2n+i-1}$ are set to $a, b, f$ respectively. The function returns $2n + i - 1$. You can call add_flea at most $\mathrm{M}$ times.

You also need to call the set_output function for each integer $i$ in $[0, n-1]$ (they can be called in any order). set_output(i, id) indicates that the $i$-th bit of the output binary number is set to the value of the flea with ID id.

Examples

Input 1

1
1 10000 10000

Output 1

(output data)

Subtasks

Subtask ID Expression to Calculate
1 $(\mathrm{A} + 1) \mod 2 ^ n$
2 $(\mathrm{A} + \mathrm{B}) \mod 2 ^ n$
3 $(\mathrm{A} \times \mathrm{B}) \mod 2 ^ n$

Let $m$ be the number of calls to add_flea, and $t$ be the latest time at which the values of all fleas are determined.

Test Case ID Subtask ID Score $n$ $\mathrm{M}$ $\mathrm{T}$ Note
1 1 1 $1$ $10000$ $10000$
2 1 2 $2$ $10000$ $10000$
3 1 5 $256$ $10000$ $10000$
4 1 9 $10^5$ $5 \times 10^5$ $50$ Score is $\min \left \{ \left \lfloor \frac{5 \times 10^5 - m}{20000} \right \rfloor, 9 \right \}$
5 1 10 $10^5$ $1.5 \times 10^6$ $30$ Score is $\min \left \{30-t, 10 \right \}$
6 2 3 $2$ $10000$ $10000$
7 2 6 $233$ $10000$ $10000$
8 2 13 $10^5$ $1.2 \times 10^6$ $100$ Score is $\min \left \{ \left \lfloor \frac{1.2 \times 10^6-m}{30000} \right \rfloor, 13 \right \}$
9 2 14 $10^5$ $5 \times 10^6$ $42$ Score is $\min \left \{42-t, 14 \right \}$
10 3 4 $2$ $10000$ $10000$
11 3 7 $233$ $10^6$ $10^6$
12 3 8 $512$ $3 \times 10^6$ $255$
13 3 17 $1024$ $4 \times 10^6$ $94$ Score is $\min \left \{ \left \lfloor\frac{94-t}{2} \right \rfloor, 17 \right \}$
14 3 1 $1024$ $1920000$ $288$

Implementation Details

This problem only supports C++.

You must submit a single source file implementing the build_computer function as described above, following the naming and interface conventions.

You need to include the header file king.h.

void build_computer(int task_id, int n, int M, int T);

The interfaces for add_flea and set_output are as follows:

int add_flea(int a, int b, int f);
void set_output(int i, int id);

Evaluation

The evaluation system will read data in the following format:

  1. Line 1: Subtask ID
  2. Line 2: $n, \mathrm{M}, \mathrm{T}$

If the number of calls to add_flea exceeds $\mathrm{M}$, or the number of calls to set_output is not equal to $n$, or you do not call set_output for every integer in $[0, n-1]$ as the first parameter, your program will be judged as "Incorrect".

After build_computer returns, if there exists a flea whose value is not determined within $\mathrm{T}$ hours, the evaluation system will output "Incorrect". Otherwise, we will test your computer with several sets of inputs. If your output is correct for all input data, the evaluation system will output "Correct", otherwise it will output "Incorrect".

If the evaluation system outputs "Correct" on the first line, the second line will output $m$ and $t$ (definitions see "Subtasks"), otherwise it will output specific error information.

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.