#P15841. [Bulgarian NOI 2024] 公平 / Fair

[Bulgarian NOI 2024] 公平 / Fair

Problem Description

Felicia Day likes playing DnD. For this, she needs various NN-sided dice. But she is a bit short on money, so to save some, she bought KK dice during a sale. However, she found that not all dice are fair (a die is fair if and only if each face has the same probability of appearing). More precisely, each die is fair with probability PP; if it is unfair, then the probability of each face is generated as follows:

  1. For ii from 11 to NN, generate a random number between 00 and 11, denoted as QiQ_i.
  2. The probability that face ii appears equals QiQ1+Q2+⋯+QN\frac{Q_i}{Q_1 + Q_2 + \cdots + Q_N}.

We can view a fair die as a die where all QiQ_i values are equal.

Felicia is eager to determine which dice are fair and which are not, but time is limited, so she rolled each die MM times. She recorded the results, that is, how many times each face appeared for each die, but she is not sure how to analyze this data. Please write a program to help her classify the dice as “fair” or “unfair”. Of course, 100% correctness is not required. Instead, each mistake will be penalized: if you classify a fair die as unfair, the penalty is XX; if you classify an unfair die as fair, the penalty is YY. Your goal is to minimize the total penalty.

Input Format

Read NN, MM, PP, XX, and YY from the first line of standard input. The next line contains KK. In the following KK lines, each line contains NN integers: the jj-th number on the ii-th line indicates the number of times face jj appeared on the ii-th die.

Output Format

For each die, output on a separate line in standard output 1 if you classify it as a fair die, or 0 if you classify it as an unfair die.

3 15 0.6 0.35 0.65
4
4 7 4
5 5 5
9 5 1
3 6 6
0
1
0
1

Hint

Sample 1 Explanation

It turns out that this solution classifies dice 22 and 33 correctly, but misclassifies dice 11 and 44. The penalty from the first mistake is 0.350.35, and the penalty from the second mistake is 0.650.65. The total penalty is 1.01.0.

Constraints

  • 2≤N≤82 \le N \le 8
  • 15≤M≤4015 \le M \le 40
  • 0.5≤P≤0.80.5 \le P \le 0.8
  • 0.3≤X,Y≤0.70.3 \le X, Y \le 0.7
  • X+Y=1X + Y = 1
  • K=100000K = 100000

Scoring

Each test point is scored independently. The score for a given test point is computed as follows:

  1. Let TP\text{TP} be the total penalty value of the mistakes made by your solution.
  2. AP=TPK\text{AP} = \frac{\text{TP}}{K}
  3. BAP=min⁡(P×X, (1−P)×Y)\text{BAP} = \min(P \times X,\ (1 - P) \times Y)
  4. $S = \max\left(\frac{\text{BAP} - \text{AP}}{\text{BAP}},\ 0\right)$
  5. R=SSAuthorR = \frac{S}{S_{\text{Author}}}
  6. Your score is:$$\begin{cases} 0.3 + 0.7 \times \left(1 - \left(1 - \frac{R - 0.8}{1 - 0.8}\right)^{0.75}\right) & \text{if } R \ge 0.8 \\ \frac{0.3}{0.8} \times R & \text{if } R < 0.8 \end{cases}$$

Translated by ChatGPT 5