#P10062. Latin Square Completion
Latin Square Completion
Latin Square Completion
We define an \(n \times n\) matrix \(A\) as a Latin square if and only if every row and every column is a permutation of \(\{1, 2, \ldots, n\}\). You are given the top-left \(R \times C\) submatrix of \(A\); that is, the entries \(A_{i,j}\) for \(1 \le i \le R\) and \(1 \le j \le C\). Determine whether it is possible to fill the remaining positions with numbers such that the resulting matrix is a Latin square.
Note: A Latin rectangle (a partially filled Latin square whose filled cells form a contiguous block in the top-left corner) can always be completed to a full Latin square if it does not violate the Latin square conditions. Hence, your task is to check if the given \(R \times C\) submatrix is a valid Latin rectangle.
inputFormat
The first line contains three integers \(n\), \(R\) and \(C\) (\(1 \le R, C \le n\)). The next \(R\) lines each contain \(C\) integers. Each integer is between 1 and \(n\) (inclusive), representing the given entries in the submatrix.
outputFormat
Output a single line containing Yes
if it is possible to complete the matrix to form a Latin square; otherwise, output No
.
sample
3 2 2
1 2
3 1
Yes