#P9071. [CTS2023] 鸽子(无防作弊)

    ID: 10118 远端评测题 3000ms 2048MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2023交互题Special Judge通信题CTSC/CTS

[CTS2023] 鸽子(无防作弊)

Background

Xiao E and Xiao F are a pair of best friends.

Problem Description

This is a communication problem.

Xiao E has some very important information to send to Xiao F. The information can be represented by a binary integer of at most 128128 bits.

However, Xiao E only has pigeons now. Lots and lots of pigeons. Black pigeons and white pigeons.

Xiao E can let pigeons of different colors take off in a certain order and fly to Xiao F. Then Xiao F can figure out the exact information from the color order of the pigeons as they land. Of course, the number of pigeons must be agreed on in advance and fixed; otherwise, before seeing all the pigeons, Xiao F might mistakenly think that all pigeons have already flown by.

But as everyone knows, the word “pigeon” is always associated with “time”. Pigeons may “stand you up”. However, Xiao E’s pigeons are fairly punctual: the difference between the takeoff order and the landing order will not exceed a positive integer kk. Formally, suppose the ii-th pigeon to take off is the pip_i-th to land. Then {pi}\{p_i\} is a permutation, and for all ii, ipik\left|i-p_i\right|\le k.

Xiao E has naturally considered these situations and has agreed on them with Xiao F in advance. If you were Xiao E, how would you make the agreement and send the information?

Implementation Details

[Note]: To submit this problem, you need to add extern "C" before all functions.

You do not need to and should not implement the main function. You need to implement three functions: pigeon_num, send, and receive.

The interface of pigeon_num is:

int pigeon_num(int Taskid, int k);
  • This function takes the subtask ID Taskid and the value of parameter k in the statement.
  • This function should return the number of pigeons nn that Xiao E needs to send.

The interface of send is:

std::string send(int Taskid, int n, int k, __uint128_t msg);
  • This function takes the subtask ID Taskid, the return value n of pigeon_num, the parameter k in the statement, and the message msg to be sent.
  • This function should return a string of length exactly nn. The position with index i(0i<n)i(0\le i\lt n) represents the color of the (i+1)(i+1)-th pigeon that Xiao E sends: 0 means black, and 1 means white.

The interface of receive is:

__uint128_t receive(int Taskid, int k, const std::string &msg);
  • This function takes the subtask ID Taskid, the parameter k in the statement, and the landing order msg seen by Xiao F.
  • msg is a string of length nn. The position with index i(0i<n)i(0\le i\lt n) represents the color of the (i+1)(i+1)-th pigeon that Xiao F sees landing: 0 means black, and 1 means white. The value of msg has the relationship described in the statement with the return value of some call to send.
  • This function should correctly return the information sent by Xiao E.

You may refer to the sample program pigeon.cpp provided, or you may write a program from scratch.

During evaluation, the interactive library will be run twice, and time and memory are counted independently for the two runs.

In the first run, the interactive library will call pigeon_num once, and then call send no more than 10001000 times.

In the second run, the interactive library will call receive no more than 1000010000 times.

It is guaranteed that under the problem limits, the evaluation interactive library runs in no more than 1s1\texttt{s} and uses no more than 512MB512\textrm{MB} of memory. That is, the time you can actually use is at least 2s2\texttt{s}, and the memory is at least 1.5GB1.5\textrm{GB}.

Since Luogu does not currently support judging communication problems, the judging logic is similar to the provided interactive library. This means it is easy to cheat. E_Space will not pursue cheating behavior here, but please do not write it in the solution.

How to Run the Test Program

Put the sample interactive library grader.cpp and your code pigeon.cpp in the same directory, and compile in the terminal with the following command:

g++ pigeon.cpp grader.cpp -o grader -g -Wall --std=c++11

Then run ./grader. The sample interactive library uses standard input and standard output, and only needs to be run once.

Note that the provided interactive library is implemented differently from the one used in the actual evaluation. For example, in the provided interactive library, the value of a global variable modified in send can be seen by receive.

Input Format

The first line contains three non-negative integers Taskid\mathrm{Taskid}, kk, TT. Here, Taskid\mathrm{Taskid} is the subtask ID, and TT is the number of messages to be sent.

The next TT lines each contain one non-negative 128128-bit integer, representing the content of a message.

Output Format

If your program is correct on this test point, then for each message, the interactive library will output four lines.

  • The first line Message is the information Xiao E wants to send, i.e., the value of parameter msg in send.
  • The second line Taking off is the takeoff order of the pigeons, i.e., the return value of send.
  • The third line Landing is the landing order of the pigeons, i.e., the value of parameter msg in receive.
  • The fourth line Received is the information decoded by Xiao F, i.e., the return value of receive.
  • The last line outputs Accepted using <num> pigeon(s)., where <num> is the number of pigeons Xiao E sent, i.e., the return value of pigeon_num.

Otherwise, if the program exits normally, the interactive library will output one of the following messages:

  • Invalid number of pigeons.: This means the return value of pigeon_num is not in [1,4000][1,4000].
  • Invalid color of pigeon.: This means the return value of send contains a character other than 0 or 1.
  • Too few or too many pigeons taking off.: This means the length of the return value of send is not equal to the return value of pigeon_num.
  • Received wrong message.: This means the return value of receive is not equal to the parameter msg in send.

Once the interactive library outputs an error message, it will stop immediately.

0 6 1
97429867398990605044182047185430790478
Message:    97429867398990605044182047185430790478
Taking off: 10101
Landing:    10011
Received:   97429867398990605044182047185430790478

Accepted using 5 pigeons.

Hint

Sample Explanation

This is the output of the sample interactive library when running the provided sample program pigeon.cpp on the sample input.

For Xiao E, 9742986739899060504418204718543079047897429867398990605044182047185430790478 is a very meaningful number. So only a small number of pigeons is enough.

Subtasks

Subtask 00 (0.010.01 points): Sample. It is guaranteed that the integer corresponding to the message equals 9742986739899060504418204718543079047897429867398990605044182047185430790478. The provided pigeon.cpp can pass the sample. The judging result of this subtask will be shown in the judging results.

Subtask 11 (3.993.99 points): It is guaranteed that the integer corresponding to the message is less than 10241024. k20k\le 20.

Subtask 22 (1212 points): k=1k=1. It is guaranteed that the integer corresponding to the message is less than 10485761048576.

Subtasks 393\sim 9 (each subtask 1212 points, 8484 points in total): k20k\le 20.

Since Luogu does not support fractional scores, the displayed score of this problem will be multiplied by 100100 to represent the result after keeping two decimal places.

Scoring

During evaluation, you only need to submit your source code on the OJ. Modifying other provided files will not affect the evaluation result.

This problem is first subject to the same limits as traditional problems. For example, a compilation error will cause the whole problem to score 00 points; runtime error, time limit exceeded, memory limit exceeded, etc. will cause the corresponding test points to score 00 points. You may only access variables defined by yourself and those given by the interactive library, as well as their corresponding memory spaces. Attempting to access other spaces may lead to compilation errors or runtime errors.

For each subtask, if your program has any of the following behaviors, it will be judged as 00 points:

  • The return value of pigeon_num is not in [1,4000][1,4000].
  • The length of the return value of send is not equal to the return value of pigeon_num.
  • The return value of send contains characters other than 0 or 1.
  • receive does not correctly return the information sent by Xiao E.

In addition, for each subtask, your score is related to the number of pigeons Xiao E sends, i.e., the return value of pigeon_num. Let this value be nn.

In subtasks 121 \sim 2, if n4000n\le 4000, you can get full score for this test point; otherwise you get 00.

In subtasks 393\sim 9, within the same subtask, all test points have the same value of kk, and in higher-numbered subtasks, the value of kk is larger. Let C(k)C(k) be a function of kk. Then:

  • If nC(k)n\le C(k), you can get full score for this test point.
  • If nC(k)+5n\le C(k)+5, then within this range, for each increase of 11 in nn, you lose 2%2\% of the full score of this test point.
  • If C(k)+5<n1.1×C(k)C(k)+5 \lt n\le \lfloor 1.1\times C(k)\rfloor, then within this range, for each increase of 11 in nn, you additionally lose 400%/C(k)400\%/C(k) of the full score of this test point.
  • If n>1.1×C(k)n\gt \lfloor 1.1\times C(k)\rfloor, then within this range, for each increase of 11 in nn, you additionally lose 40%/C(k)40\%/C(k) of the full score of this test point.
  • If your answer is correct, you can get at least 11 point.

In other words, your score on a test point is max(1,12×min(1,fk(n)))\max(1, 12\times \min(1, f_k(n))), where fk(n)f_k(n) is a piecewise linear function of nn satisfying:

  • fk(C(k))=1f_k(C(k))=1.
  • The xx-coordinates of the two breakpoints are C(k)+5C(k)+5 and 1.1×C(k)\lfloor 1.1\times C(k)\rfloor.
  • The slopes of the three segments formed by the two breakpoints are, in order, 0.02-0.02, 4/C(k)-4/C(k), and 0.4/C(k)-0.4/C(k).

Your score for each subtask is the minimum score among all test points in the subtask.

The value of C(k)C(k) is given in the table below. The values of kk not appearing in the table will not appear in the testdata of subtasks 393\sim 9.

kk 11 22 55 77 1010 1414 2020
C(k)C(k) 206206 284284 485485 605605 773773 983983 12771277

Gaining score by accessing input/output files, attacking the judging system, or attacking the judging library, etc., is cheating behavior, and the score obtained is invalid.

Since Luogu does not currently support judging communication problems, the judging logic is similar to the provided interactive library. This means it is easy to cheat. E_Space will not pursue cheating behavior here, but please do not write it in the solution.

Translated by ChatGPT 5