CF1250M.SmartGarden

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Berland Gardeners United Inc. hired you for the project called "SmartGarden". The main feature of this project is automatic garden watering.

Formally the garden can be represented as a square of n×nn \times n cells with rows numbered 11 to nn from top to bottom and columns numbered 11 to nn from left to right. Each cell of the garden contains either a plant or a slab.

It's known that slabs are located on the main diagonal of the matrix representing the garden, and in the cells that are below the main diagonal and share a side with at least one cell of the main diagonal. All the remaining cells of the garden are filled with plants.

Example of the garden for n=5n=5.

During implementation of the project you created a smart robot that takes a list of commands as an input, which are processed one by one. Each command contains:

  • a list of horizontal lines (rows in the matrix representing the garden);
  • a list of vertical lines (columns in the matrix representing the garden).

While executing each command robot waters only cells in the intersection of specified rows and specified columns. So, if you specify rr rows and cc columns, then exactly r⋅cr \cdot c cells will be watered.

In the demo for the customer you have tuned robot in such a way that it waters all the garden. To do that you prepared a single command containing all nn rows and all nn columns.

Unfortunately, 5 hours before the demo for your customer it turned out that the CEO of Berland Gardeners United Inc. was going to take part in it. Moreover, most probably he will be standing on a garden slab during the demo!

Now you need to create a list of commands for the robot so that it waters all the plants and doesn't water any cell containing a slab. Since it's only a beta version of "SmartGarden", the total number of commands shouldn't exceed 5050.

Create a program that, for a given size of the garden, will find a list of no more than 5050 commands that allow the robot to water all the plants in the garden without watering the slabs. It is allowed to water a plant several times.

伯兰德园丁联合公司(Berland Gardeners United Inc.)聘请您参与名为“SmartGarden”的项目。该项目的核心功能是自动花园浇灌。

形式化地,花园可表示为一个 n×nn \times n 的方格,行号从上到下依次为 11 至 nn,列号从左到右依次为 11 至 nn。花园的每个格子中要么种有一株植物,要么铺设有一块石板。

已知:石板位于表示花园的矩阵的主对角线上,以及位于主对角线下方、且与主对角线上的至少一个格子共享一条边的所有格子中。花园其余所有格子均种植有植物。

n=5n=5 时花园的一个示例。

在项目实现过程中,您开发了一台智能机器人,它接收一个命令列表作为输入,并逐条执行这些命令。每条命令包含:

  • 一组水平线(即花园矩阵中的若干行);
  • 一组垂直线(即花园矩阵中的若干列)。

执行每条命令时,机器人仅浇灌所指定行与所指定列之交集中的格子。因此,若指定 rr 行和 cc 列,则恰好有 r⋅cr \cdot c 个格子被浇灌。

在面向客户的演示中,您已将机器人调校为浇灌整个花园:为此,您准备了单条命令,其中包含了全部 nn 行和全部 nn 列。

不幸的是,在客户演示开始前 5 小时,得知伯兰德园丁联合公司的首席执行官(CEO)将亲自出席该演示;而且,他极有可能在演示期间站在花园的一块石板上!

现在,您需要为机器人生成一份命令列表,使得它能浇灌所有植物,但不浇灌任何含石板的格子。由于“SmartGarden”目前仅为测试版,命令总数不得超过 5050 条。

请编写一个程序:对于给定的花园尺寸 nn,找出至多 5050 条命令,使机器人能够浇灌花园中所有植物,且不浇灌任何石板。允许同一株植物被多次浇灌。

输入格式

The first and the only line of the input contains a single integer nn (2≤n≤50002 \le n \le 5000), where nn is the size of the garden.

输入仅有一行,包含一个整数 nn(2≤n≤50002 \le n \le 5000),表示花园的大小。

输出格式

In the first line print the total number of commands for the robot kk (1≤k≤501 \le k \le 50). In the next 2⋅k2 \cdot k lines print all the commands. Each command should be specified by 22 lines. The first line of each command should describe rows in the command and the second line should describe columns in the command. Each of these 22 lines should have the following format:

  • the first number of the line should specify the total number of items xx in the appropriate list;
  • then xx distinct numbers follow, where each number is in the range 1…n1 \dots n and describes a chosen row for the first line and a chosen column for the second line.

If there are multiple ways to water the garden, print any of them.

第一行输出机器人所需执行的指令总数 kk(1≤k≤501 \le k \le 50)。接下来的 2⋅k2 \cdot k 行输出全部指令。每条指令需用两行表示:第一行描述该指令所涉及的行,第二行描述该指令所涉及的列。这两行的格式如下:

  • 每行的第一个数字表示该行中元素的总数 xx;
  • 接着是 xx 个互不相同的整数,每个整数均在 1…n1 \dots n 范围内,分别表示第一行中选定的行号和第二行中选定的列号。

若存在多种方式可浇灌整个花园,输出任意一种即可。

输入输出样例

  • 输入#1

    2

    输出#1

    2
    1 1
    1 2
    1 1
    1 2
  • 输入#2

    4

    输出#2

    4
    2 1 4
    1 2
    2 1 2
    2 3 4
    1 3
    2 1 4
    1 4
    1 1

输入解题思路,AI测评打分。不知道怎么写?

首页