MaxNiceMatrixDiv1
TCO18 Fun Round Beijing · 2018-04-20 · by ltdtl
Problem Statement
You are given three integers a, b, and c where a and b are non-negative and c is positive. A matrix X is said to be a nice (a,b,c)-matrix if the following conditions are met:
- Every element of X is an integer between a and b, inclusive.
- The matrix has exactly c columns.
- In each column of X all the elements are distinct.
- The sum of each row of X is equal to b+(c-1)*a.
Note that different nice (a,b,c)-matrices may have different numbers of rows. For instance, the following three matrices are nice (1,3,3)-matrices:
matrix 1 (1 row, 3 columns):
1 3 1
matrix 2 (1 row, 3 columns):
1 2 2
matrix 3 (2 rows, 3 columns):
2 2 1
1 1 3
There are many other nice (1,3,3)-matrices. It can be shown that each nice (1,3,3)-matrix has either one or two rows.
You are given the three
Suppose you constructed the matrix X with r rows and c columns.
Return an array (a variable of type
{
X[0][0], X[0][1], ..., X[0][c-1],
X[1][0], X[1][1], ..., X[1][c-1],
...,
X[r-1][0], X[r-1][1], ..., X[r-1][c-1]
}
If there are multiple optimal matrices, you may return any of them.
Constraints
- a will be between 0 and 1,000,000, inclusive.
- b will be between 0 and 1,000,000, inclusive.
- c will be between 2 and 50, inclusive.
- (b-a) will be between (c-1) and 1,000, inclusive.
1
3
3
Returns: {2, 2, 1, 1, 1, 3 }
This example is discussed in the problem statement. Note that there are other correct return values, for example {1, 3, 1, 2, 1, 2}.
1
3
2
Returns: {2, 2, 1, 3, 3, 1 }
5
10
3
Returns: {5, 5, 10, 7, 6, 7, 6, 8, 6, 8, 7, 5 }
The return value describes the following matrix: 5 5 10 7 6 7 6 8 6 8 7 5 We can easily verify that this is a nice (5,10,3)-matrix: the values in each column are distinct and the sum of each row is 20.
10
13
4
Returns: {10, 10, 10, 13, 11, 11, 11, 10 }
3
10
5
Returns: {3, 3, 3, 3, 10, 5, 4, 4, 4, 5, 4, 5, 5, 5, 3 }
Submissions are judged against all 207 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MaxNiceMatrixDiv1 with a public method vector<int> getMaxMatrix(int a, int b, int c) · 207 test cases · 2 s / 256 MB per case