Connection Status:
Competition Arena > TAASquares
SRM 784 · 2020-04-23 · by misof · Math, Recursion
Class Name: TAASquares
Return Type: String[]
Method Name: construct
Arg Types: (int)
Problem Statement

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[].

Constraints

  • N will be between 1 and 50, inclusive.
Examples
0)
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.

1)
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.

2)
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.

3)
2
Returns: {"00", "12" }
4)
3
Returns: {"000", "012", "122" }

Submissions are judged against all 50 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TAASquares with a public method vector<string> construct(int N) · 50 test cases · 2 s / 256 MB per case

Submitting as anonymous