Vestigium means "trace" in Latin. In this problem, we work with Latin squares and matrix traces.
The trace of a square matrix is the sum of the values on the main diagonal (which runs from the upper left to the lower right).
An
Given a matrix that contains only integers between 1 and
Input Specification
The first line of the input gives the number of test cases,
Output Specification
For each test case, output one line containing Case #x: k r c
, where
Limits
Test set 1
Time limit: 20 seconds per test set.
Memory limit: 1GB.
Sample Input
3
4
1 2 3 4
2 1 4 3
3 4 1 2
4 3 2 1
4
2 2 2 2
2 3 2 3
2 2 2 3
2 2 2 2
3
2 1 3
1 3 2
1 2 3
Sample Output
Case #1: 4 0 0
Case #2: 9 4 4
Case #3: 8 0 2
In Sample Case #1, the input is a natural Latin square, which means no row or column has repeated elements. All four values in the main diagonal are 1, and so the trace (their sum) is 4.
In Sample Case #2, all rows and columns have repeated elements. Notice that each row or column with repeated elements is counted only once regardless of the number of elements that are repeated or how often they are repeated within the row or column. In addition, notice that some integers in the range 1 through
In Sample Case #3, the leftmost and rightmost columns have repeated elements.
Comments