#P10888. 【MX-S3-T4】「FeOI Round 1」醒餞の鳥 (feat. Feryquitous)
【MX-S3-T4】「FeOI Round 1」醒餞の鳥 (feat. Feryquitous)
Background
Original link: https://oier.team/problems/S3D。
Problem Description
There are students (numbered ) taking an exam with subjects (numbered ). You are given that student 's score in subject is 。
Now you want to rank these students. Since it is hard to compare the ability of two students whose scores do not form a partial order, you plan to set real numbers (required to satisfy and ) as weights. Define student 's weighted total score as . Then students are ranked in descending order of weighted total score, and students with equal weighted total score share the same rank。
Now all subject teachers have made requests to you. The teacher of subject wants your chosen to satisfy:
- In the ranking result obtained by this , there does not exist a pair of students () such that ranks higher (ties do not count), but 。
Because you want to distribute the weights as freely as possible, for each (), you need to compute separately:
- What is the minimum value of such that no matter how the other are distributed, the teacher of subject 's requirement is always satisfied? Output the result modulo 。
Input Format
This problem contains multiple test cases within a single input file.
The first line contains an integer denoting the number of test cases。
For each test case, the format is:
The first line contains two integers 。
Lines to each contain integers. The integer in row , column denotes 。
Output Format
For each test case, output lines, each containing a non-negative integer. The -th line represents the result when , i.e., the minimum value of modulo 。
That is, suppose the answer in lowest terms is , where and are coprime. Output an integer such that and 。It can be proven that such an integer is unique。
4
4 4
4 2 4 3
1 3 1 2
1 2 4 2
4 2 4 3
10 2
1 2
4 0
3 1
2 4
0 5
2 3
3 2
1 1
2 2
4 4
4 4
0 0 0 0
0 0 0 0
1 0 1 0
0 0 0 0
2 10
92603107 17358677 20869254 22085089 68529385 51524980 47064864 17692636 31121387 37022044
25517267 69562538 61254114 54886162 15087981 27505611 76082026 59892091 54661294 59475460
748683265
249561089
748683265
499122177
399297742
399297742
0
0
0
0
892513752
105730602
366911811
374997189
954012663
897963459
891479524
220357565
706471693
519276178
Hint
[Sample Explanation]
For the first test case, the answers before taking modulo are respectively。
For the second test case, the answers before taking modulo are respectively。
For the third test case, the answers before taking modulo are respectively。
For the query with in the first test case, suppose :
- Student 's weighted total score is $4 \times 0.1 + 2 \times 0.75 + 4 \times 0.1 + 3 \times 0.05 = 2.45$;
- Student 's weighted total score is $1 \times 0.1 + 3 \times 0.75 + 1 \times 0.1 + 2 \times 0.05 = 2.55$;
- Student 's weighted total score is $1 \times 0.1 + 2 \times 0.75 + 4 \times 0.1 + 2 \times 0.05 = 2.1$;
- Student 's weighted total score is $4 \times 0.1 + 2 \times 0.75 + 4 \times 0.1 + 3 \times 0.05 = 2.45$;
Then you rank the students (by descending weighted total score) as (of course it can also be ). Also, $a_{2, 2} = 3, a_{4, 2} = 2, a_{1, 2} = 2, a_{3, 2} = 2$, and there is no case where a lower-ranked student has a higher score in subject 。
It can be proven that when , no matter how the other are distributed, the requirement can be satisfied; while when , there must exist a distribution of the other that makes the requirement impossible to satisfy。
[Constraints]
This problem uses bundled tests.
Let be the sum of all over all test cases within a single input file。
For of the testdata, , , , 。
| Subtask ID | Special Property | Score | |||
|---|---|---|---|---|---|
| None | |||||
| None | |||||
Translated by ChatGPT 5