#P9380. [THUPC 2023 决赛] 总投票数

[THUPC 2023 决赛] 总投票数

Background

Dear players of La Lumière: Scarlet Intense Flame - Adventurous Scarlet -:

It has been a great honor to spend these four wonderful years with you. We sincerely thank everyone for your support and companionship.

Now, we regret to announce that La Lumière: Scarlet Intense Flame - Adventurous Scarlet - will stop operating at 15:00 on May 28, 2023.

The shutdown schedule is as follows:

……

Problem Description

Before the shutdown, the operators launched a series of polls to find out which game content left a deeper impression on players.

As a loyal player of the series, you want to know how many people participated in the polls before the shutdown. However, the operators only made the final poll results public: for a poll with NN options, the proportion of players who chose option ii is PiP_i (1iN1 \le i \le N). When publishing the results, the operators rounded the numbers, and each PiP_i is kept to the LL-th digit after the decimal point. Suppose in reality there are KK players participating in the poll, and DiD_i players chose option ii. Then we should have

$$P_i-\frac{1}{2}\times 10^{-L}\le\frac{D_i}{K}< P_i+\frac{1}{2}\times 10^{-L}$$

Clearly, all DiD_i must be non-negative integers, and K=i=1NDiK=\sum_{i=1}^N D_i must be a positive integer. Now, given NN and PiP_i, please find the smallest total number of votes KK such that DiD_i has a non-negative integer solution.

Input Format

The first line contains a positive integer NN, indicating the total number of options in the poll. It is guaranteed that 1N1001 \le N \le 100.

The next NN lines each contain a real number PiP_i in [0,1][0, 1], indicating the proportion of players who chose option ii. It is guaranteed that i=1NPi=1\sum_{i=1}^N P_i = 1. All PiP_i are kept to the LL-th digit after the decimal point, and 1L61 \le L \le 6.

Output Format

Output a positive integer, indicating the minimum total number of votes KK that satisfies the requirements.

3
0.166667
0.333333
0.500000

6

7
0.041096
0.109589
0.109589
0.164384
0.301370
0.068493
0.205479

73

13
0.00155
0.03876
0.01584
0.05189
0.08099
0.06825
0.15658
0.10404
0.02640
0.14332
0.12941
0.15529
0.02768

7766

Hint

[Sample Explanation #1]

The minimum total number of votes is 66, and the corresponding votes for each option are 1,2,31, 2, 3.

[Sample Explanation #2]

The minimum total number of votes is 7373, and the corresponding votes for each option are 3,8,8,12,22,5,153, 8, 8, 12, 22, 5, 15.

[Sample Explanation #3]

The minimum total number of votes is 77667766, and the corresponding votes for each option are $12, 301, 123, 403, 629, 530, 1216, 808, 205, 1113, 1005, 1206, 215$.

[Constraints]

For all testdata, 1N1001 \le N \le 100, 0Pi10 \le P_i \le 1, i=1NPi=1\sum_{i=1}^N P_i = 1, and all PiP_i are kept uniformly to at most 66 digits after the decimal point.

[Source]

From the finals of the 2023 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2023).

Solutions and other resources can be found at https://github.com/THUSAAC/THUPC2023.

Translated by ChatGPT 5