TopcoderArchiveVisit Topcoder
TCO20 Apr 2018
TCO18 Beijing

MaxNiceMatrixDiv1

Problem statement, definition, constraints, and public examples.

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:

  1. Every element of X is an integer between a and b, inclusive.
  2. The matrix has exactly c columns.
  3. In each column of X all the elements are distinct.
  4. 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 ints a, b, and c. Construct a nice (a,b,c)-matrix with as many rows as possible.


Suppose you constructed the matrix X with r rows and c columns. Return an array (a variable of type int[]) that contains all the elements of X in row-major order. In other words, return the following:

{
    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.

Definition

Class:
MaxNiceMatrixDiv1
Method:
getMaxMatrix
Parameters:
int, int, int
Returns:
int[]
Method signature:
int[] getMaxMatrix(int a, int b, int c)
(be sure your method is public)

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.

Examples

  1. 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}.
  2. 1
    3
    2
    Returns: {2, 2, 1, 3, 3, 1 }
  3. 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.
  4. 10
    13
    4
    Returns: {10, 10, 10, 13, 11, 11, 11, 10 }
  5. 3
    10
    5
    Returns: {3, 3, 3, 3, 10, 5, 4, 4, 4, 5, 4, 5, 5, 5, 3 }
Back to all problems