#P15092. [UOI 2025 II Stage] Diagonal Numbers

    ID: 17008 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2025Special Judge构造UOI(乌克兰)

[UOI 2025 II Stage] Diagonal Numbers

题目描述

Vasylko was given cubes with numbers from 11 to nn. One cube had the number nn, two cubes had the number n1n-1, and so on, with n1n-1 cubes having the number 22, and nn cubes having the number 11.

He arranged the cubes in a square frame without a top boundary, so that all cubes were placed below the diagonal that runs from the top left corner to the bottom right corner. In the first column on the left, there are nn cubes with the number 11; in the second column, there are n1n-1 cubes with the number 22... in the nn-th column, there is one cube with the number nn. That is, in the ii-th column, there are ni+1n-i+1 cubes with the number ii.

:::align{center}

Initial state :::

Vasylko wanted to rearrange them so that all cubes were positioned below the opposite diagonal\textbf{opposite diagonal}. Thus, in the first row from the bottom, there should be nn cubes with the number 11; in the second row, there should be n1n-1 cubes with the number 22... in the nn-th row, there should be one cube with the number nn. That is, in the ii-th row, there should be ni+1n-i+1 cubes with the number ii.

:::align{center}

Final state :::

He also decided that he would only move cubes from the top of one column to the top of another (not necessarily adjacent). Help him do this in the most efficient way --- find the minimum number of moves he needs and output which moves Vasylko should make.

$\textbf{You can earn partial points; see details below.}$

输入格式

The first line contains one integer nn (3n1000)(3 \le n \le 1000) --- the size of the square.

输出格式

In the first line, output one integer kk (1k1061 \leq k \leq 10^6) --- the minimum number of moves needed to rearrange the cubes.

In each of the following kk lines, output two integers aa and bb (1a,bn1 \leq a, b \leq n; aba \neq b), where aa is the column number from which you take a cube, and bb is the column number to which you place the cube.

3
8
3 2
1 3
2 1
2 3
1 3
2 3
1 2
3 2

提示

First, we will place the last column. Therefore, the only first move to rearrange the cubes in the minimum number of moves may be to move 33 from the third column to the second, because otherwise we will not be able to place 11 at the beginning of the third column if we do not move 33 or do not move it to the second column.

:::align{center}

First 3 states :::

After we have placed 11, we need to place 22 and 33 in their places in the third column, again the only way to do this is to first move 33 to the first column, because otherwise we will not be able to place 22 in the third column in the next move, and then place 33 in its place.

:::align{center}

Next 3 states :::

After this, we want to correctly place the second column, and for 11 to be the first number, we first need to take 22, which we can only take in the last column. After we have placed 11, we only need to return 22 to the second column to achieve the desired state of the cubes.

:::align{center}

Final 3 states :::

Scoring

  • (1212 points): n=4n = 4;
  • (2020 points): n=5n = 5;
  • (2020 points): n=6n = 6;
  • (2020 points): n10n \le 10;
  • (2020 points): n100n \le 100;
  • (88 points): no additional restrictions.

You can earn half the points for each block if you output the correct kk for each test in the block. You will also receive a quarter of the points if you output an incorrect kk, but the instructions are correct; in this case, k106k \le 10^6.

Note that to earn half the points, you need to output the correct kk and

  • either output nothing else; that is, output only kk, but no instructions;
  • or output all kk instructions completely, where all column numbers are from 11 to nn. There are no additional requirements for them.

If you output, for example, only a few instructions, or too many instructions, or numbers that are not column numbers, etc., you will receive 00 points.