#P7876. Score Table Reconstruction
Score Table Reconstruction
Score Table Reconstruction
This problem is about reconstructing an exam score table based on pairwise score comparisons among n students over m subjects. For each student i and subject j, the score si,j is an integer satisfying \(0 \le s_{i,j} \le 100\).
The comparisons among students are given by a matrix \(a\) (with \(a_{i,j}\) defined for \(i \neq j\)) with the following meaning:
- \(a_{i,j} = 0\) means that student i is totally dominated by student j, i.e. \(s_{i,k} < s_{j,k}\) holds for all subjects \(k = 1,2,\dots,m\). (In short, student j "吊打" student i.)
- \(a_{i,j} = 1\) means that student i is not worse than student j, i.e. there exists at least one subject \(k\) such that \(s_{i,k} > s_{j,k}\).
Although these two conditions (being totally dominated versus not worse) are not logical complements in full generality, the provided matrix \(a\) satisfies in fact that for any two distinct students i and j, either \(a_{i,j} = 0\) or \(a_{i,j} = 1\) (and consequently \(a_{j,i}\) is the complementary value). In other words, for every pair \(i \neq j\) we have:
[ a_{i,j} + a_{j,i} = 1. ]
Moreover, it is observed that if two different students are both totally dominated by some other student, or both totally dominate some other student, then there is an order between them in the sense that one is totally dominated by the other. In a valid score table \(s\), these facts force the following: For every two distinct students \(i\) and \(j\), the score vectors \(s_i = (s_{i,1}, s_{i,2}, \dots, s_{i,m})\) and \(s_j\) must be comparable in the natural partial order. That is, either
[ s_{i,k} < s_{j,k} ;\text{for all } k \quad (\text{in which case } a_{i,j}=0 \text{ and } a_{j,i}=1), ]
or
[ s_{i,k} > s_{j,k} ;\text{for all } k \quad (\text{in which case } a_{i,j}=1 \text{ and } a_{j,i}=0). ]
Your task is to determine whether there exists a score table \(s\) satisfying the relationships given by \(a\). If such a table exists, output YES
and any one valid score table; otherwise output NO
.
Note: When the score table exists, there must be a permutation \(P\) of \(\{1,2,\dots,n\}\) such that for all \(i
[ s_{P(i),k} < s_{P(j),k} \quad \text{for all } k=1,2,\dots,m. ]
A natural way to satisfy these constraints is to assign each student a constant score (for all subjects) according to the total order. In such a table, if student i comes before student j in the total order then (a_{i,j}) must be 0 and vice versa.
inputFormat
The first line contains two integers n and m \((1 \le n \le 101, 1 \le m \le 10)\) representing the number of students and the number of subjects.
The next \(n\) lines each contain \(n\) integers. The \(j\)th integer in the \(i\)th line denotes \(a_{i,j}\). For any \(i\), the value \(a_{i,i}\) can be any number (and should be ignored). For any \(i \neq j\), it is guaranteed that \(a_{i,j} \in \{0,1\}\) and \(a_{i,j} + a_{j,i} = 1\).
outputFormat
If a valid score table exists, first output YES
on a line. Then output n lines, each containing m space‐separated integers. The ith line should denote the scores of student i in the m subjects. It must hold that \(0 \le s_{i,j} \le 100\) for all i,j, and the score table must satisfy the conditions described in the problem statement.
If no valid score table exists, simply output NO
.
sample
3 2
0 0 0
1 0 0
1 1 0
YES
0 0
1 1
2 2