MaxMinMax

3.6

9 votes
Mathematics, Basic Math, Easy, Mathematics
Problem

Given N, you must build an N×N matrix consisting of integer values from 1 to N.

Each value should appear exactly N times in the matrix.
The score of an array is defined as the greatest frequency of one element in the array. The score of a matrix is defined as the minimum score over all rows and columns. 

Build a matrix with the greatest possible score.

Input:

The first line contains an integer, representing N.

Output:

Print N lines each containing N integers.

Notes and constaints:

1N11

Let O be the optimal score for a test and S be your score for a certain test case.

Then the test will be graded with max(0,10025OSO4) points.

Sample Input
2
Sample Output
1 1
2 2
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

The maximum frequency in [1,1] is 2. The maximum frequency in [2,2] is 2. The maximum frequency in [1,2] is 1.

Therefore, the score of this matrix is 1 and this is the best that we can, for N=2.

Editor Image

?