TopcoderARCHIVE
Archive/Problems/TAASquares
SRM · Problem 16111

TAASquares

Problem statement, definition, constraints, and public examples.

Problem Statement

Given a matrix, we will use the term lines to denote both rows and columns of that matrix. For example, a 5x5 matrix has ten lines.

A ternary almost-antimagic square (TAA square) is a square matrix with the following properties:

  • Each cell contains one of the digits 0, 1, 2.
  • The set containing the sums of all individual lines in the matrix has as many (distinct) elements as possible.

Given N, construct and return any N x N TAA square as a String[].

Definition

Class:
TAASquares
Method:
construct
Parameters:
int
Returns:
String[]
Method signature:
String[] construct(int N)
(be sure your method is public)

Constraints

  • N will be between 1 and 50, inclusive.

Examples

  1. 4
    Returns: {"2212", "2002", "0002", "2102" }
    The row sums are 7, 4, 2, and 5. The column sums are 6, 3, 1, and 8. All eight values are distinct.
  2. 5
    Returns: {"12222", "00012", "02221", "00110", "00122" }
    There are nine distinct line sums. In particular, row 2 is 0+2+2+2+1 = 7 and column 4 is 2+2+1+0+2 = 7.
  3. 1
    Returns: {"1" }
    The only row has sum 1 and the only column has sum 1. Clearly, the row sum must be the same as the column sum so you cannot do better.
← All problems