#P7876. 「SWTR-7」Scores(hard version)
「SWTR-7」Scores(hard version)
Description
There are students in Xiao A's class. Recently, they took an exam with subjects. The score of student in subject is an integer .
Students care a lot about their rank in the class, so they often compare their scores with others. If a student has a higher score than in at least one subject, then they feel that they are not worse than . On the other hand, if they have a lower score than in every subject, then they feel they are completely crushed by .
In fact, the two situations above are not strictly opposite. However, Xiao A, who loves gossip, learned the score relationship between every pair of students, and he was surprised to find that: a student is either crushed by , or not worse than . At the same time, if and are both crushed by the same person, or they both crush the same person, then between and one of them is crushed by the other. We use a matrix to describe the relationships Xiao A knows: means is crushed by ; means is not worse than .
Xiao A wants to know whether such a situation can actually happen, i.e. whether there exists an score table that satisfies the score relationships described by matrix , so as to determine whether someone lied. If such an exists, first output , then output any valid score table that meets the requirements. Otherwise, output .
Note: the required conditions on are exactly the constraints given by , not only the properties Xiao A discovered, because those discovered properties are already reflected in the given .
Input Format
This problem contains multiple test cases.
The first line contains an integer , which indicates the test point ID.
The second line contains an integer , which indicates the number of test cases.
For each test case:
The first line contains two integers .
Then follow lines, each containing space-separated 0 or 1 values describing . The -th number in line represents .
In particular, to make input easier, it is defined that . But you should know that it has no actual meaning.
Output Format
For each test case:
If there is no that satisfies the conditions, output one line with the string .
Otherwise, first output one line with the string , then output lines, each containing space-separated integers. The -th number in line represents .
0
5
5 3
0 1 1 1 1
1 0 1 1 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 0
2 7
0 1
0 0
5 4
0 1 1 0 1
0 0 0 0 1
0 1 0 0 1
1 1 1 0 1
1 1 1 1 0
3 1
0 1 1
1 0 1
1 1 0
3 2
0 1 0
0 0 1
1 0 0
YES
100 99 97
98 100 99
95 97 100
0 98 100
99 99 99
YES
98 100 94 98 72 53 53
97 99 93 97 71 52 52
YES
90 80 70 60
50 40 30 20
60 50 40 30
100 90 80 70
40 60 80 100
NO
NO
Hint
"Special Judge"
This problem uses Special Judge. Please read the output format carefully. Incorrect output format may lead to UKE or WA.
The SPJ will first check whether your first line matches the correct answer.
If it matches and the answer is , then the SPJ will check whether your output satisfies all constraints.
If a solution exists and you output but your construction is wrong, you will get of the score for that test point.
The constraints you must satisfy are:
- .
- For any , if , then for any , ; if , then there exists a such that .
You should note that all outputs must strictly follow the output format. If you correctly determine whether a solution exists, but in your output construction or , the SPJ will judge it as WA and you will get points, not the test point score.
"Constraints and Conventions"
This problem has 6 test points.
- Testcase #0 (1 point): the sample.
- Testcase #1 (10 points): .
- Testcase #2 (10 points): .
- Testcase #3 (30 points): .
- Testcase #4 (20 points): .
- Testcase #5 (29 points): no special constraints.
For of the data, , , (except Testcase #0).
For the constraints on : if , then at least one of and is ; if , then at least one of and is .
For all test points, time limit is 500 ms, memory limit is 16 MB.
"Source"
Sweet Round 07 A2.
idea & solution & data: Alex_Wei; verification: chenxia25.
Translated by ChatGPT 5
京公网安备 11011102002149号