#P10802. [CEOI 2024] 核酸检测

    ID: 12273 远端评测题 10000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2024交互题Special JudgeCEOI(中欧)

[CEOI 2024] 核酸检测

Problem Description

This problem is translated from CEOI 2024 Day 1 Task 2「COVID tests」.

A new wave of COVID has recently broken out at Adam’s school. To prevent the outbreak from spreading further, the school decided to use saliva antigen test kits to test all students.

Because the teachers have not used these kits for a long time, Adam volunteered to be a testing helper. He received saliva samples from NN students (for privacy reasons, he can only see identifiers numbered from 00 to N1N-1), and his task is to determine which samples are positive.

However, Adam soon realized that testing every student one by one is too time-consuming and tiring. Then he came up with a smarter method than testing individually. If he mixes some samples together and tests them, he can tell whether the whole mixture is all negative, or whether at least one sample is positive. This way, he can reduce the number of tests needed.

Each sample has enough saliva for multiple tests. Also, these test kits are very accurate, so the same sample will never produce different test results.

Under these conditions, Adam wants to optimize the testing process and use as few tests as possible. But since he is busy testing right now, the optimization is left to you.

From local statistics, Adam knows that the probability that any given sample is positive is PP, and whether one sample is positive or negative does not affect the test results of other samples. Maybe you can use this information to help Adam optimize the testing plan.

Input Format

This is an interactive problem.

Your program will handle multiple testdata. In each testdata (i.e., one run of your program), you need to solve TT different scenarios. In all scenarios, the number of students NN and the positive probability PP stay the same, but which students are positive (most likely) differs from scenario to scenario.

You may implement the interactive protocol yourself, or use the provided template. In the “Files” section you can find an attachment named template.cpp, which is the provided template.

First, your program should read one line from standard input containing three space-separated values N,P,TN, P, T, representing the number of students, the probability of a positive sample, and the number of scenarios.

Then, your program may output queries to standard output. Each query must be on its own line, in the format Q, a space, and a string ss of length NN. Each character sis_i is either 1 or 0. 1 means the sample of student ii should be added to the mixture for testing, and 0 means it should not be added. After outputting a query, your program must flush the output buffer, then read one character from standard input. This character will be P (meaning at least one sample in the mixture is positive) or N (meaning all samples in the mixture are negative).

Your program may also output a final answer. The answer must be on its own line, in the format A, a space, and a string ss of length NN. Each character sis_i is either 1 or 0. 1 means the sample of student ii is positive, and 0 means it is negative. After outputting an answer, your program must also flush the output buffer, then read one character from standard input.

If the read character is C, your answer is correct. In this case, your program may start processing queries for the next scenario, or if it was the answer for the TT-th scenario, it may exit.

If the read character is W, your answer is incorrect. Your program must exit immediately.

Note that exiting after receiving W is very important for the interactor to provide correct feedback. If your program continues running, it may crash or receive other wrong verdicts.

The interactor will not adapt the testdata based on how your program behaves. This means whether each sample is positive or negative is fixed before your program starts. Also, each sample’s status is determined independently by a fair random generator with probability PP.

If you implement the interaction using the protocol in template.cpp, you need to implement the function std::vector<bool> find_positive(). This function is called once in each scenario. It must return a boolean vector of length NN, where the ii-th element is true if and only if the ii-th student’s sample is positive.

During implementation, you may use the function bool test_students(std::vector<bool> mask). This function performs a mixed test on some samples. Its only parameter is a boolean array of length NN, where the ii-th element is true if the ii-th sample should be included in the mixture. The function returns true if and only if at least one sample in the mixture is positive.

You may also use the global variables N and P, which represent the total number of students and the probability of a positive sample. You may initialize them in main after the first call to scanf.

Sample Input Sample Output
10 0.4 2
Q 1000000000
P
Q 0000001000
P
Q 0000000001
P
Q 0111110110
N
A 1000001001
C
A 0000000000
W  

Hint

This problem has two subtasks.

Subtask 1 (10 points)

  • Total number of students N=1000N = 1000.
  • Number of scenarios T=1T = 1.
  • Positive probability PP is between 00 and 11.

If the program always answers correctly and the number of queries in each testdata does not exceed 22 times the total number of students 2N2N, then the program passes.

Subtask 2 (90 points)

  • Total number of students N=1000N = 1000.
  • Number of scenarios T=300T = 300.
  • Positive probability PP is between 0.0010.001 and 0.20.2.

This subtask has partial scoring.

If your program gives a wrong answer in any scenario, you will get 00 points. Otherwise, the score for each testdata is based on the average number of queries. In general, fewer queries give a higher score. Let QQ be the average number of queries over all scenarios, rounded to one digit after the decimal point. For each testdata, we compute a value FF (see below). The score for the given testdata is computed as follows:

  • If Q>10Q > 10 times FF, you will get 00 points (wrong answer).
  • If F<Q10F < Q \leq 10 times FF, the score is computed by:90FF+4(QF)90 \cdot \frac{F}{F + 4 \cdot (Q-F)}
  • If QFQ \leq F, you will get the full 9090 points.

Your program will be scored on testdata with different values of PP. Your total score is the minimum score among all testdata (all probabilities PP).

The testdata are:

PP FF
0.0010.001 15.115.1
0.0052560.005256 51.151.1
0.0115460.011546 94.994.9
0.0285450.028545 191.5191.5
0.0398560.039856 246.3246.3
0.0686480.068648 366.2366.2
0.1045710.104571 490.3490.3
0.1587650.158765 639.1639.1
0.20.2 731.4731.4

The interactor will provide feedback for each testdata. This feedback will include the average number of queries QQ on the testdata where your score is non-zero.

Translated by ChatGPT 5