306678: CF1236C. Labs

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Labs

题意翻译

现在有 $n^2$ 个点,按 $1$~$n^2$ 依次编号,编号大的点可以贡献 $1$ 点贡献给编号小的点。 现在要求将这 $n^2$ 个点分成 $n$ 组,每一组 $n$ 个点。 假设将组按照 $G_1 , G_2$~$G_n$ 编号,则定义 $f(G_i,G_j)$ 是 $G_i$ 组到 $G_j$ 组的总贡献。 假设 $G_i=\{1,5,6\},G_j=\{2,4,9\}$则 $f(G_i,G_j)=4$ $(5\rightarrow2,5\rightarrow4,6\rightarrow2,6\rightarrow4)$共 $4$ 点贡献。更多可见英语题面中翻译。 现在给出 $n$, 希望你可以求出一种分组方案,使得所有的 $f(G_i,G_j)$ 中的最小值最大。$(\min \{f(G_i,G_j)\}$最大$)$ 输入: 输入一个 $n$ ($2 \leq n\leq300$) 输出: 输出 $n$ 行,每行 $n$ 个数,表示每个分组内点的编号。

题目描述

In order to do some research, $ n^2 $ labs are built on different heights of a mountain. Let's enumerate them with integers from $ 1 $ to $ n^2 $ , such that the lab with the number $ 1 $ is at the lowest place, the lab with the number $ 2 $ is at the second-lowest place, $ \ldots $ , the lab with the number $ n^2 $ is at the highest place. To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $ u $ to the lab with the number $ v $ if $ u > v $ . Now the labs need to be divided into $ n $ groups, each group should contain exactly $ n $ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $ A $ to a group $ B $ is equal to the number of pairs of labs ( $ u, v $ ) such that the lab with the number $ u $ is from the group $ A $ , the lab with the number $ v $ is from the group $ B $ and $ u > v $ . Let's denote this value as $ f(A,B) $ (i.e. $ f(A,B) $ is the sum of units of water that can be sent from a group $ A $ to a group $ B $ ). For example, if $ n=3 $ and there are $ 3 $ groups $ X $ , $ Y $ and $ Z $ : $ X = \{1, 5, 6\}, Y = \{2, 4, 9\} $ and $ Z = \{3, 7, 8\} $ . In this case, the values of $ f $ are equal to: - $ f(X,Y)=4 $ because of $ 5 \rightarrow 2 $ , $ 5 \rightarrow 4 $ , $ 6 \rightarrow 2 $ , $ 6 \rightarrow 4 $ , - $ f(X,Z)=2 $ because of $ 5 \rightarrow 3 $ , $ 6 \rightarrow 3 $ , - $ f(Y,X)=5 $ because of $ 2 \rightarrow 1 $ , $ 4 \rightarrow 1 $ , $ 9 \rightarrow 1 $ , $ 9 \rightarrow 5 $ , $ 9 \rightarrow 6 $ , - $ f(Y,Z)=4 $ because of $ 4 \rightarrow 3 $ , $ 9 \rightarrow 3 $ , $ 9 \rightarrow 7 $ , $ 9 \rightarrow 8 $ , - $ f(Z,X)=7 $ because of $ 3 \rightarrow 1 $ , $ 7 \rightarrow 1 $ , $ 7 \rightarrow 5 $ , $ 7 \rightarrow 6 $ , $ 8 \rightarrow 1 $ , $ 8 \rightarrow 5 $ , $ 8 \rightarrow 6 $ , - $ f(Z,Y)=5 $ because of $ 3 \rightarrow 2 $ , $ 7 \rightarrow 2 $ , $ 7 \rightarrow 4 $ , $ 8 \rightarrow 2 $ , $ 8 \rightarrow 4 $ . Please, divide labs into $ n $ groups with size $ n $ , such that the value $ \min f(A,B) $ over all possible pairs of groups $ A $ and $ B $ ( $ A \neq B $ ) is maximal. In other words, divide labs into $ n $ groups with size $ n $ , such that minimum number of the sum of units of water that can be transported from a group $ A $ to a group $ B $ for every pair of different groups $ A $ and $ B $ ( $ A \neq B $ ) as big as possible. Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $ f $ for some division. If there are many optimal divisions, you can find any.

输入输出格式

输入格式


The only line contains one number $ n $ ( $ 2 \leq n \leq 300 $ ).

输出格式


Output $ n $ lines: In the $ i $ -th line print $ n $ numbers, the numbers of labs of the $ i $ -th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.

输入输出样例

输入样例 #1

3

输出样例 #1

2 8 5
9 3 4
7 6 1

说明

In the first test we can divide $ 9 $ labs into groups $ \{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\} $ . From the first group to the second group we can transport $ 4 $ units of water ( $ 8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4 $ ). From the first group to the third group we can transport $ 5 $ units of water ( $ 2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1 $ ). From the second group to the first group we can transport $ 5 $ units of water ( $ 9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2 $ ). From the second group to the third group we can transport $ 5 $ units of water ( $ 9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1 $ ). From the third group to the first group we can transport $ 4 $ units of water ( $ 7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5 $ ). From the third group to the second group we can transport $ 4 $ units of water ( $ 7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4 $ ). The minimal number of the sum of units of water, that can be transported from one group to another is equal to $ 4 $ . It can be proved, that it is impossible to make a better division.

Input

题意翻译

现在有 $n^2$ 个点,按 $1$~$n^2$ 依次编号,编号大的点可以贡献 $1$ 点贡献给编号小的点。 现在要求将这 $n^2$ 个点分成 $n$ 组,每一组 $n$ 个点。 假设将组按照 $G_1 , G_2$~$G_n$ 编号,则定义 $f(G_i,G_j)$ 是 $G_i$ 组到 $G_j$ 组的总贡献。 假设 $G_i=\{1,5,6\},G_j=\{2,4,9\}$则 $f(G_i,G_j)=4$ $(5\rightarrow2,5\rightarrow4,6\rightarrow2,6\rightarrow4)$共 $4$ 点贡献。更多可见英语题面中翻译。 现在给出 $n$, 希望你可以求出一种分组方案,使得所有的 $f(G_i,G_j)$ 中的最小值最大。$(\min \{f(G_i,G_j)\}$最大$)$ 输入: 输入一个 $n$ ($2 \leq n\leq300$) 输出: 输出 $n$ 行,每行 $n$ 个数,表示每个分组内点的编号。

加入题单

算法标签: